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


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

    do i = 1, m
        read*, a(i),b(i),c(i)
    end do
    
    sc(1:n)=-inf*2000000
    sc(1)=0

    do i = 1,n-1
        do j = 1,m
            if (sc(a(j))+c(j) > sc(b(j))) then
                sc(b(j)) = sc(a(j))+c(j)
            end if
            ! print*, sc
        end do
    end do

    is_updated(1:n) = .false.

    do i = 1,n-1
        do j = 1,m
            if (sc(a(j))+c(j) > sc(b(j))) then
                sc(b(j)) = sc(a(j))+c(j)
                is_updated(b(i)) = .true.
            end if
            if (is_updated(a(i)))then
                is_updated(b(i)) = .true. 
            end if
            ! print*, sc
        end do
    end do

    if (is_updated(n)) then
        print*, 'inf'
    else
        print*, sc(n)
    end if




end program