#include <iostream>
using namespace std;
int main()
{
int x;
int t = 1, ans = 0;
while (cin >> x, x)
{
if (x == 1)
t = 1;
else if (x == 2)
{
if (t % 2 == 0) t += 2;
else t = 2;
}
ans += t;
}
cout << ans << endl;
}