program sample
    implicit none
    
    integer(8) :: i,j,m,n
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n
    allocate(x(n))
    read(*,*)x
    m=x(1)
    do i=1,n-1
        if(x(i+1)>x(i))then
            m=m+x(i+1)-x(i)
        end if
    end do
    write(*,*)m
    stop
end program sample
  

