n = gets.to_i
h = gets.split.map(&:to_i)
total = h.inject(:+)
sum = 0
count = 0
while sum < total do
  i = 0
  while i < n && h[i] == 0 do
    i += 1
  end
  while i < n && h[i] > 0 do
    h[i] -= 1
    sum += 1
    i += 1
  end
  count += 1
end
puts count
