## main

loop do
  n = gets.strip.to_i
  break if n == 0

  cs = [-1]

  for i in (1..n)
    ci = gets.strip.to_i

    if (i & 1) == 1
      cs[i] = ci
    else
      i0 = i
      while i0 > 0 && cs[i0 - 1] == 1 - ci
        i0 -= 1
      end
      for k in (i0..i)
        cs[k] = ci
      end
    end
  end

  puts cs.select{|c| c == 0}.length
end