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

l=[list(map(int,input().split())) for i in range(m)]

distance=[float('inf')]*n

distance[0]=0

for i in range(n-1):

  for j in range(m):

    if distance[l[j][1]-1]>distance[l[j][0]-1]-l[j][2]:

      distance[l[j][1]-1]=distance[l[j][0]-1]-l[j][2]

x=distance[n-1]

for i in range(n):

  for j in range(m):

    if distance[l[j][1]-1]>distance[l[j][0]-1]-l[j][2]:

      distance[l[j][1]-1]=-float('inf')

if distance[n-1]==x:

  print((-distance[n-1]))

else:

  print('inf')
(n,m),*l=[list(map(int,s.split()))for s in open(0)];d=[0]*2+[9e99]*n

for i in range(n*2):

 for a,b,c in l:

  if d[b]>d[a]-c:d[b]=[d[a]-c,-9e99][i>n]

 if i==n:x=d[n]

print(([-x,'inf'][d[n]!=x]))
n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
distance = [float("inf")] * n
distance[0] = 0
for i in range(n - 1):
    for j in range(m):
        if distance[l[j][1] - 1] > distance[l[j][0] - 1] - l[j][2]:
            distance[l[j][1] - 1] = distance[l[j][0] - 1] - l[j][2]
x = distance[n - 1]
for i in range(n):
    for j in range(m):
        if distance[l[j][1] - 1] > distance[l[j][0] - 1] - l[j][2]:
            distance[l[j][1] - 1] = -float("inf")
if distance[n - 1] == x:
    print((-distance[n - 1]))
else:
    print("inf")

(n, m), *l = [list(map(int, s.split())) for s in open(0)]
d = [0] * 2 + [9e99] * n
for i in range(n * 2):
    for a, b, c in l:
        if d[b] > d[a] - c:
            d[b] = [d[a] - c, -9e99][i > n]
    if i == n:
        x = d[n]
print(([-x, "inf"][d[n] != x]))

-n, m = list(map(int, input().split())) -l = [list(map(int, input().split())) for i in range(m)] -distance = [float("inf")] * n -distance[0] = 0 -for i in range(n - 1): -    for j in range(m): -        if distance[l[j][1] - 1] > distance[l[j][0] - 1] - l[j][2]: -            distance[l[j][1] - 1] = distance[l[j][0] - 1] - l[j][2] -x = distance[n - 1] -for i in range(n): -    for j in range(m): -        if distance[l[j][1] - 1] > distance[l[j][0] - 1] - l[j][2]: -            distance[l[j][1] - 1] = -float("inf") -if distance[n - 1] == x: -    print((-distance[n - 1])) -else: -    print("inf") +(n, m), *l = [list(map(int, s.split())) for s in open(0)] +d = [0] * 2 + [9e99] * n +for i in range(n * 2): +    for a, b, c in l: +        if d[b] > d[a] - c: +            d[b] = [d[a] - c, -9e99][i > n] +    if i == n: +        x = d[n] +print(([-x, "inf"][d[n] != x]))