# main

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

  stack = []
  prvc = -1

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

    if (i & 1) == 0
      if prvc != ci
        stack << [i, ci]
      end
    else
      if prvc == 1 - ci
        stack.pop
        if stack.empty?
          stack << [0, ci]
        end
      end
    end

    prvc = ci
  end

  if stack.last[1] == 0
    stack << [n, 1]
  end

  len = 0

  for i in (0...stack.length)
    if stack[i][1] == 0
      len += stack[i + 1][0] - stack[i][0]
    end
  end

  p len
end