program main
    implicit none
    integer:: n,m, i,j,k
    integer, allocatable:: a(:), b(:)
    integer(8), allocatable:: c(:), sc(:), nsc(:)
    integer(8):: inf = 1000000000
    logical:: is_updated


    read*, n, m
    allocate(a(m), b(m), c(m), sc(n), nsc(n))

    do i = 1, m
        read*, a(i),b(i),c(i)
    end do
    
    sc(1:n)=-inf*2000000; nsc(1:n)=-inf*2000000
    sc(1)=0; nsc(1)=0
    i = 0
    is_updated = .true.
    do while(is_updated .eqv. .true.)
        i = i + 1
        is_updated = .false.
        do j = 1,m
            if (sc(a(j))+c(j) > sc(b(j))) then
                sc(b(j)) = sc(a(j))+c(j)
                is_updated = .true.
            end if
            ! print*, sc
        end do
        if (i > m+1)then
            print*, 'inf'
            stop
        end if
    end do

    print*, sc(n)


end program