n = gets.to_i
hs = gets.split.map(&:to_i)
ans = 0
1.upto(hs.max) do |h|
  cnt = 0
  bool = false
  n.times do |i|
    if !bool && hs[i] - h >= 0
      bool = true
      cnt += 1
    elsif bool && hs[i] - h < 0
      bool = false
    end
  end
  ans += cnt
end
puts ans