N, *h = $stdin.read.split(/\s/).map(&:to_i)

count = 0
while not (h.all? 0)
  i = 0
  i += 1 while (i < h.size) and (h[i] == 0)

  while (i < h.size) and (h[i] != 0)
    h[i] -= 1
    i += 1
  end

  count += 1
end

puts count
