#include <iostream>
using namespace std;
int main()
{
int a[30];
int aa;
int i=1;
cin>>aa;
while(aa>0)
{
a[i]=aa;
i++;
cin>>aa;
}
int Count=0;
int temp[i];//temp数组储存的是每一次的得分 就是为了方便出现连续正中间的时候,计算后一个的得分
for(int j=1;j<=i;j++)
{
if(a[j]==1){temp[j]=1;}//跳在方块上得分直接加一
if(a[j]==2)
{
if(j>=2&&(temp[j-1]>=2))//如果连续跳在方块上,那么就在上一次的得分基础上在加两分作为本次得分
{
temp[j]=temp[j-1]+2;
}
else
{
temp[j]=2;
}
}
}
for(int j=1;j<i;j++)
{
Count+=temp[j];
}
cout << Count << endl;
return 0;
}