loop {
	n = gets.to_i
	break if n == 0
	stone = (1..n).map { gets.to_i }
	a = []
	(0..n-1).each{|i|
		if i.even?
			if !a.empty? && a[-1][0] == stone[i]
				a[-1][1] += 1
			else
				a << [stone[i], 1]
			end
		else
			if a[-1][0] == stone[i]
				a[-1][1] += 1
			else
				_, k = a.pop
				if a.empty?
					a << [stone[i], k+1]
				else
					a[-1][1] += k + 1
				end
			end
		end
	}
	p a.map{|c, k| c == 0 ? k : 0}.inject(:+)
}