program main
  implicit none
  integer :: n, i, res
  integer, allocatable :: h(:)
  read(*, *) n
  allocate(h(0:n))
  h(0) = 0
  read(*, *) h(1:)

  res = 0
  do i = 1, n
    res = res + max(0, h(i) - h(i - 1))
  end do

  write (*, "(i0)") res
end program main
