n = gets.chomp.to_i
h = gets.chomp.split(" ").map { |e| e.to_i }

max = h.max
record = Array.new(n,0)

ans = 0


for i in 1..max+1 do

  for k in 0..n-1 do
    if 1 <= k
      if h[k-1] != 0 && h[k] == 0
        ans += 1
      end
    end
  end
  if h[n-1] != 0
    ans += 1
  end


  for j in 0..n-1 do
    if h[j] != 0
      h[j] -= 1
    end
  end
end

puts ans
