N,M = list(map(int,input().split()))

edge = [0]*M

for i in range(M):

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

    a -= 1

    b -= 1

    c *= -1

    edge[i] = (a,b,c)



inf = float('inf')

V = N

E = M

d = [inf]*V

d[0] = 0

for i in range(V):

    for j in range(E):

        From,To,cost = edge[j]

        if d[From] != inf and d[To]>d[From]+cost:

            d[To]=d[From]+cost

ans = d[N-1]

for i in range(V):

    for j in range(E):

        From,To,cost = edge[j]

        if d[From] != inf and d[To]>d[From]+cost:

            d[To]=d[From]+cost



if d[N-1]!=ans:

    print('inf')

else:

    print((-ans))
N,M = list(map(int,input().split()))

edge = [0]*M

for i in range(M):

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

    a -= 1

    b -= 1

    c *= -1

    edge[i] = (a,b,c)



inf = float('inf')

V = N

E = M

d = [inf]*V

d[0] = 0

for i in range(V):

    update = False

    for j in range(E):

        From,To,cost = edge[j]

        if d[From] != inf and d[To]>d[From]+cost:

            d[To]=d[From]+cost

            update = True

    if not update:

        break

ans = d[N-1]

for j in range(E):

    From,To,cost = edge[j]

    if d[From] != inf and d[To]>d[From]+cost:

        d[To]=d[From]+cost



if d[N-1]!=ans:

    print('inf')

else:

    print((-ans))
N, M = list(map(int, input().split()))
edge = [0] * M
for i in range(M):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    c *= -1
    edge[i] = (a, b, c)
inf = float("inf")
V = N
E = M
d = [inf] * V
d[0] = 0
for i in range(V):
    for j in range(E):
        From, To, cost = edge[j]
        if d[From] != inf and d[To] > d[From] + cost:
            d[To] = d[From] + cost
ans = d[N - 1]
for i in range(V):
    for j in range(E):
        From, To, cost = edge[j]
        if d[From] != inf and d[To] > d[From] + cost:
            d[To] = d[From] + cost
if d[N - 1] != ans:
    print("inf")
else:
    print((-ans))

N, M = list(map(int, input().split()))
edge = [0] * M
for i in range(M):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    c *= -1
    edge[i] = (a, b, c)
inf = float("inf")
V = N
E = M
d = [inf] * V
d[0] = 0
for i in range(V):
    update = False
    for j in range(E):
        From, To, cost = edge[j]
        if d[From] != inf and d[To] > d[From] + cost:
            d[To] = d[From] + cost
            update = True
    if not update:
        break
ans = d[N - 1]
for j in range(E):
    From, To, cost = edge[j]
    if d[From] != inf and d[To] > d[From] + cost:
        d[To] = d[From] + cost
if d[N - 1] != ans:
    print("inf")
else:
    print((-ans))

+    update = False +            update = True +    if not update: +        break -for i in range(V): -    for j in range(E): -        From, To, cost = edge[j] -        if d[From] != inf and d[To] > d[From] + cost: -            d[To] = d[From] + cost +for j in range(E): +    From, To, cost = edge[j] +    if d[From] != inf and d[To] > d[From] + cost: +        d[To] = d[From] + cost