n=gets.chomp.to_i
h=gets.chomp.split.map(&:to_i)
miz = 0
loop do
  100.times do
   begin;h.shift if h[0] == 0 ||h[0].negative?;rescue;end
   begin;h.pop if h[-1] == 0 ||h[-1].negative?;rescue;end
  end
  if h.size==0
   break
  else
   miz+=h.join(",").scan(/(,0|,-\d+){1,}/).size+1
  end
  h.map!{|a|a-1}
end
puts miz