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

E = []

for i in range(M):

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

    a, b = a - 1, b - 1

    c = -c

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



dist = [float('inf')] * (N+1)

dist[0] = 0



for n in range(N):

    for a, b, c in E:

        if (dist[a] != float('inf')) & (dist[b] > dist[a] + c):

            dist[b] = dist[a] + c

            if (n == N - 1) & (b == N - 1):

                print('inf')

                exit()



print((-dist[N - 1]))

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

Edges = []

for i in range(M):

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

    a, b = a - 1, b - 1

    c = -c

    Edges.append([a, b, c])



dist = [float('inf')] * N

dist[0] = 0



for i in range(N):

    for fr, to, cost in Edges:

        if (dist[fr] != float('inf')) and (dist[to] > dist[fr] + cost):

            dist[to] = dist[fr] + cost

            if (i == N - 1) & (to == N - 1):

                print('inf')

                exit()



print((-dist[-1]))

N, M = list(map(int, input().split()))
E = []
for i in range(M):
    a, b, c = list(map(int, input().split()))
    a, b = a - 1, b - 1
    c = -c
    E.append([a, b, c])
dist = [float("inf")] * (N + 1)
dist[0] = 0
for n in range(N):
    for a, b, c in E:
        if (dist[a] != float("inf")) & (dist[b] > dist[a] + c):
            dist[b] = dist[a] + c
            if (n == N - 1) & (b == N - 1):
                print("inf")
                exit()
print((-dist[N - 1]))

N, M = list(map(int, input().split()))
Edges = []
for i in range(M):
    a, b, c = list(map(int, input().split()))
    a, b = a - 1, b - 1
    c = -c
    Edges.append([a, b, c])
dist = [float("inf")] * N
dist[0] = 0
for i in range(N):
    for fr, to, cost in Edges:
        if (dist[fr] != float("inf")) and (dist[to] > dist[fr] + cost):
            dist[to] = dist[fr] + cost
            if (i == N - 1) & (to == N - 1):
                print("inf")
                exit()
print((-dist[-1]))

-E = [] +Edges = [] -    E.append([a, b, c]) -dist = [float("inf")] * (N + 1) +    Edges.append([a, b, c]) +dist = [float("inf")] * N -for n in range(N): -    for a, b, c in E: -        if (dist[a] != float("inf")) & (dist[b] > dist[a] + c): -            dist[b] = dist[a] + c -            if (n == N - 1) & (b == N - 1): +for i in range(N): +    for fr, to, cost in Edges: +        if (dist[fr] != float("inf")) and (dist[to] > dist[fr] + cost): +            dist[to] = dist[fr] + cost +            if (i == N - 1) & (to == N - 1): -print((-dist[N - 1])) +print((-dist[-1]))