require 'pp'

N = readline.to_i
hi = readline.split.map(&:to_i)

hmax = hi.max

def count_flip(arg)
  a = [false] + arg
  cnt = 0
  (1..a.size).each do |i|
    cnt += 1 if !(a[i-1]) and a[i]
  end
  cnt
end

sum = 0
(1..hmax).each do |h|
  a = hi.map {|x| x >= h }
  # pp a
  sum += count_flip(a)
end

puts sum
