N = gets.to_i
h = gets.chomp.split.map(&:to_i)

max_h = h.max
ans = 0
(1..max_h).each do |cur|
  N.times do |i|
    ans += 1 if (i == 0 and h[i] >= cur) or (h[i - 1] < cur and h[i] >= cur)
  end
end

puts ans