n = gets.to_i
h = gets.chomp.split(" ").map(&:to_i)
cnt = 0
n.times do |i|
  while h[i] != 0
    j = i
    while j <= n-1
      if h[j] > 0
        j += 1
      else
        break
      end
    end
    if i <= j-1
      i.upto(j-1) do |k|
        h[k] -= 1
      end
      cnt += 1
    end
  end
end
puts cnt
