#
# Setting Go Stones
#
while (n=gets.to_i)!=0

  stone=[]
  count=[]

  stone<<gets.chomp
  count<<1

  2.upto(n) do |i|
    s=gets.chomp
    if i.even?
      if stone[-1]!=s
        stone[-1]=s
        count[-1]+=1
        if stone[-2]!=s
          stone[-2]=s
          count[-2]+=count[-2]
          stone.pop
          count.pop
        end
      else
        count[-1]+=1
      end
    else
      if stone[-1]==s
        count[-1]+=1
      else
        stone<<s
        count<<1
      end
    end
  end

  sum=0
  stone.each_with_index do |s, i|
    sum+=count[i] if s=='0'
  end
  puts sum

end