N = gets.to_i

hs = gets.split.map{|i| i.to_i }
 
sum = 0
 

hs.length.times do |i|
  while hs[i] > 0
    hs[i] -= 1
    sum += 1
    for j in 1..hs.length - i - 1 do
      break if(hs[i+j] <= 0)
      hs[i+j] -= 1
    end
  end

end

puts sum