program garden
  integer n,ans,i,flag
  integer,allocatable :: h(:)

  read *, n
  allocate(h(n))
  read *, h
  ans = 0
  do while (maxval(h) > 0)
    flag = 0!search flowers to water
    do i = 1, n
      if (h(i) /= 0 .and. flag == 0) then
        h(i) = h(i) - 1
        flag = 1!watering now
        ans = ans + 1
      else if (h(i) /=0 .and. flag == 1) then
        h(i) = h(i) - 1
      else if (h(i) == 0 .and. flag == 1) then
        exit
      end if
    end do
  end do
  print '(i0)', ans


end program garden