import sys

from copy import deepcopy



n, m = [int(i) for i in input().split()]

es = [[int(j) for j in input().split()] for i in range(m)]



x = [float('-inf')] * (n+1)

x[1] = 0

border = sys.maxsize // 1000



for i in range(n):

    for a, b, c in es:

        x[b] = max(x[b], x[a]+c)

        if x[b] >= border:

            x[b] = float('inf')



prevxn = x[n]

for a, b, c in es:

        x[b] = max(x[b], x[a]+c)



if prevxn != x[n]:

    print('inf')

else:

    print((x[n]))
from copy import deepcopy



n, m = [int(i) for i in input().split()]

es = [[int(j) for j in input().split()] for i in range(m)]



x = [float('-inf')] * (n+1)

x[1] = 0



for i in range(n):

    for a, b, c in es:

        x[b] = max(x[b], x[a]+c)



prevxn = x[n]

for a, b, c in es:

        x[b] = max(x[b], x[a]+c)



if prevxn != x[n]:

    print('inf')

else:

    print((x[n]))
import sys
from copy import deepcopy

n, m = [int(i) for i in input().split()]
es = [[int(j) for j in input().split()] for i in range(m)]
x = [float("-inf")] * (n + 1)
x[1] = 0
border = sys.maxsize // 1000
for i in range(n):
    for a, b, c in es:
        x[b] = max(x[b], x[a] + c)
        if x[b] >= border:
            x[b] = float("inf")
prevxn = x[n]
for a, b, c in es:
    x[b] = max(x[b], x[a] + c)
if prevxn != x[n]:
    print("inf")
else:
    print((x[n]))

from copy import deepcopy

n, m = [int(i) for i in input().split()]
es = [[int(j) for j in input().split()] for i in range(m)]
x = [float("-inf")] * (n + 1)
x[1] = 0
for i in range(n):
    for a, b, c in es:
        x[b] = max(x[b], x[a] + c)
prevxn = x[n]
for a, b, c in es:
    x[b] = max(x[b], x[a] + c)
if prevxn != x[n]:
    print("inf")
else:
    print((x[n]))

-import sys -border = sys.maxsize // 1000 -        if x[b] >= border: -            x[b] = float("inf")