N = gets.to_i
Hn = gets.split.map(&:to_i)

max = Hn.max

count = 0
max.times do |i|
  succ = false
  Hn.each do |h|
    if h >= i
      count += 1 unless succ
      succ = true
    else
      succ = false
    end
  end
end

p count
