integer N,M
integer(16),allocatable::a(:),b(:),c(:)
integer(16),allocatable::dist(:)
integer(16) ans

logical,allocatable::negative(:)


read*,N,M
allocate( a(M),b(M),c(M) )
do i=1,M
  read*,a(i),b(i),c(i)
  c(i)=-c(i)
end do

allocate(dist(N))
dist=huge(a(J))/2
dist(1)=0
do i=1,N-1
  do j=1,M
    if(dist(a(j))==huge(a(j))/2)cycle
    if (dist(b(j)) > dist(a(j))+c(j) )dist(b(j))= dist(a(j))+ c(j)
  end do
end do
ans=dist(N)

allocate(negative(N))
negative=.false.
do i=1,N
  do j=1,M
   if (dist(a(j)) == INF)cycle
   if (dist(b(j)) > dist(a(j)) + c(j) )then
     dist(b(j)) = dist(a(j)) + c(j)
     negative(b(j)) = .true.
   endif
   if (negative(a(j)) ) negative(b(j)) =.true.
  end do
end do

if(negative(N))then
  print"(A)","inf"
else
  print"(i0)",-ans
end if
end