n,m=list(map(int,input().split()))

e=[]

for _ in range(m):

    a,b,c=list(map(int,input().split()))

    e.append([a-1,b-1,-c])

M=10**18

d=[0]+[M]*~-n

k=0

v=0

while k<n*2:

    k+=1

    if k==n:v=d[-1]

    f=0

    for a,b,c in e:

        if d[b]>d[a]+c:

            d[b]=d[a]+c

            f=1

    if not f:

        break

if not v or v==d[-1]:

    print((-d[-1]))

else:

    print('inf')
from scipy.sparse import*

m=csr_matrix

n,*t=list(map(int,open(0).read().split()))

s=[n+1]*2

r,c,d=t[1::3],t[2::3],[-c for c in t[3::3]]

u=set(csgraph.depth_first_order(m((d,(c,r)),s),n,1,0))

r,c,d=list(zip(*[(r,c,d)for r,c,d in zip(r,c,d)if r in u and c in u]))

try:print((-int(csgraph.bellman_ford(m((d,(r,c)),s),1,[1])[0,n])))

except:print('inf')
n, m = list(map(int, input().split()))
e = []
for _ in range(m):
    a, b, c = list(map(int, input().split()))
    e.append([a - 1, b - 1, -c])
M = 10**18
d = [0] + [M] * ~-n
k = 0
v = 0
while k < n * 2:
    k += 1
    if k == n:
        v = d[-1]
    f = 0
    for a, b, c in e:
        if d[b] > d[a] + c:
            d[b] = d[a] + c
            f = 1
    if not f:
        break
if not v or v == d[-1]:
    print((-d[-1]))
else:
    print("inf")

from scipy.sparse import *

m = csr_matrix
n, *t = list(map(int, open(0).read().split()))
s = [n + 1] * 2
r, c, d = t[1::3], t[2::3], [-c for c in t[3::3]]
u = set(csgraph.depth_first_order(m((d, (c, r)), s), n, 1, 0))
r, c, d = list(zip(*[(r, c, d) for r, c, d in zip(r, c, d) if r in u and c in u]))
try:
    print((-int(csgraph.bellman_ford(m((d, (r, c)), s), 1, [1])[0, n])))
except:
    print("inf")

-n, m = list(map(int, input().split())) -e = [] -for _ in range(m): -    a, b, c = list(map(int, input().split())) -    e.append([a - 1, b - 1, -c]) -M = 10**18 -d = [0] + [M] * ~-n -k = 0 -v = 0 -while k < n * 2: -    k += 1 -    if k == n: -        v = d[-1] -    f = 0 -    for a, b, c in e: -        if d[b] > d[a] + c: -            d[b] = d[a] + c -            f = 1 -    if not f: -        break -if not v or v == d[-1]: -    print((-d[-1])) -else: +from scipy.sparse import * + +m = csr_matrix +n, *t = list(map(int, open(0).read().split())) +s = [n + 1] * 2 +r, c, d = t[1::3], t[2::3], [-c for c in t[3::3]] +u = set(csgraph.depth_first_order(m((d, (c, r)), s), n, 1, 0)) +r, c, d = list(zip(*[(r, c, d) for r, c, d in zip(r, c, d) if r in u and c in u])) +try: +    print((-int(csgraph.bellman_ford(m((d, (r, c)), s), 1, [1])[0, n]))) +except: