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

E = []

for _ in range(M):

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

    E.append((a,b,c))

dist = [-N*10**9]*(N+1)

dist[1] = 0

flag = False

for i in range(N):

    for (a,b,c) in E:

        newlen = dist[a] + c

        if newlen > dist[b]:

            if i == N-1:

                flag = True

            dist[b] = newlen

            predist = dist[N]



dist2 = dist.copy()

for i in range(N):

    for (a,b,c) in E:

        newlen = dist2[a] + c

        if newlen > dist2[b]:

            dist2[b] = newlen

if dist2[N] > dist[N]:

    print("inf")

else:

    print((dist[N]))
N, M = list(map(int, input().split()))

E = []

for _ in range(M):

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

    E.append((a,b,c))

dist = [-N*10**9]*(N+1)

dist[1] = 0

flag = False

for i in range(N):

    for (a,b,c) in E:

        newlen = dist[a] + c

        if newlen > dist[b]:

            dist[b] = newlen

    if i == N-1 and dist[N] > predist:

        flag =True

    predist = dist[N]



if flag:

    print("inf")

else:

    print((dist[N]))
N, M = list(map(int, input().split()))
E = []
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    E.append((a, b, c))
dist = [-N * 10**9] * (N + 1)
dist[1] = 0
flag = False
for i in range(N):
    for (a, b, c) in E:
        newlen = dist[a] + c
        if newlen > dist[b]:
            if i == N - 1:
                flag = True
            dist[b] = newlen
            predist = dist[N]
dist2 = dist.copy()
for i in range(N):
    for (a, b, c) in E:
        newlen = dist2[a] + c
        if newlen > dist2[b]:
            dist2[b] = newlen
if dist2[N] > dist[N]:
    print("inf")
else:
    print((dist[N]))

N, M = list(map(int, input().split()))
E = []
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    E.append((a, b, c))
dist = [-N * 10**9] * (N + 1)
dist[1] = 0
flag = False
for i in range(N):
    for (a, b, c) in E:
        newlen = dist[a] + c
        if newlen > dist[b]:
            dist[b] = newlen
    if i == N - 1 and dist[N] > predist:
        flag = True
    predist = dist[N]
if flag:
    print("inf")
else:
    print((dist[N]))

-            if i == N - 1: -                flag = True -            predist = dist[N] -dist2 = dist.copy() -for i in range(N): -    for (a, b, c) in E: -        newlen = dist2[a] + c -        if newlen > dist2[b]: -            dist2[b] = newlen -if dist2[N] > dist[N]: +    if i == N - 1 and dist[N] > predist: +        flag = True +    predist = dist[N] +if flag: