DBG = true
n = gets.to_i
h = gets.split.map{|x| x.to_i}
cnt = 0
for i in 1..100
  cnt += 1 if h[0] >= 1
  for j in 1...n
    cnt += 1 if h[j-1] == 0 && h[j] >= 1
  end
  for j in 0...n
    h[j] -= 1 if h[j] >= 1
  end
end
puts "#{cnt}"
