import java.util.Scanner;
public class Main
{
public static void main (String[] args)
{
Scanner scanner=new Scanner(System.in);
int score=0;
int sum=0;
int n=0;
while((n=scanner.nextInt())!=0)
{
if(n==1)
{
score=1;
}
else if(n==2&&score%2!=0)
{
score=2;
}
else if(n==2&&score%2==0)
{
score+=2;
}
sum+=score;
}
System.out.println(sum);
}
}