n = gets.to_i
h = gets.split.map(&:to_i)

ans = 0

while !h.count(0) != n
  prev = 0
  n.times do |i|
    if h[i] == 0 && i == 0
      prev += 1
      next
    elsif h[i] == 0 && h[i-1] == 0
      prev += 1
      next
    elsif h[i] == 0 && i!=0 && h[i-1] != 0
      ans += 1
      h[prev..(i-1)] = h[prev..(i-1)].map{|j| j-1}
      prev = i+1
      next
    elsif i == n-1
      ans += 1
      h[prev..i] = h[prev..i].map{|j| j-1}
      prev = 0
      next
    end
  end
end

puts ans