program garden
  implicit none

  integer :: n, min, max, i, cnt, j, k, t, s
  integer, allocatable :: h(:), h2(:)

  read(*,*) n
  allocate(h(n))
  allocate(h2(n))
  read(*,*) h

  min = minval(h)
  max = maxval(h)


     cnt = min

  
  do j = min, max
     do t = 1, n
        if(h(t) >= j) then
           h2(t) = h(t) - j 
        else
           h2(t) = 0
        end if

        
     end do
     
     do i = 1, n
        if (h2(i) >= 1) then
           if(product(h2(i:n)) == 0) then
              do k = i, n
                 if(h2(k) == 0) then
                    do s = i, k
                       h2(s) = 0
                    end do
                    
                    cnt = cnt + 1
                    exit
                 end if
              end do
              
           else
              cnt = cnt + 1
              exit
           end if
        end if
     end do
     
  end do

  write(*,*) cnt
end program garden

           
