program main
    implicit none
    integer(8), parameter:: inf = 2**32 -1
    integer(4):: n,m, i,j,k
    integer(8), allocatable:: a(:),b(:),c(:)
    integer(8), allocatable:: dist(:)

    read*, n, m
    allocate(a(m), b(m), c(m), dist(n))
    do i = 1, m
        read*, a(i),b(i),c(i)
    end do

    dist(1:n) = inf
    dist(1) = 0
    c = c*(-1)
    do j = 1, m
        do i = 1, m
            if (dist(b(i)) <= dist(a(i)) + c(i))cycle
            dist(b(i)) = dist(a(i)) + c(i)
            if(j <= m-1) cycle
            print*, 'inf'
            stop
        end do
    end do

    print*, -dist(n)



end program