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

dp = [-float("INF")]*(N+1)

dp[1] = 0

edges = [list(map(int,input().split())) for _ in range(M)]

cnt = 0

while cnt < N:

    cnt += 1

    for a,b,c in edges:

        dp[b] = max(dp[a]+c,dp[b])

tmp = dp[N]

cnt = 0

while cnt < N:

    cnt += 1

    for a,b,c in edges:

        dp[b] = max(dp[a]+c,dp[b])

if dp[N] > tmp:

    print("inf")

else:

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

edges = []

for _ in range(M):

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

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



cost = [-float("INF")]*(N+1)

cost[1] = 0

cnt = 0

flag = True

for _ in range(N):

    for a,b,c in edges:

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

            cost[b] = cost[a]+c



tmp = cost[N]



for _ in range(N):

    for a,b,c in edges:

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

            cost[b] = cost[a]+c



if tmp < cost[N]:

    print("inf")

else:

    print(tmp)



N, M = list(map(int, input().split()))
dp = [-float("INF")] * (N + 1)
dp[1] = 0
edges = [list(map(int, input().split())) for _ in range(M)]
cnt = 0
while cnt < N:
    cnt += 1
    for a, b, c in edges:
        dp[b] = max(dp[a] + c, dp[b])
tmp = dp[N]
cnt = 0
while cnt < N:
    cnt += 1
    for a, b, c in edges:
        dp[b] = max(dp[a] + c, dp[b])
if dp[N] > tmp:
    print("inf")
else:
    print((dp[N]))

N, M = list(map(int, input().split()))
edges = []
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    edges.append((a, b, c))
cost = [-float("INF")] * (N + 1)
cost[1] = 0
cnt = 0
flag = True
for _ in range(N):
    for a, b, c in edges:
        if cost[a] + c > cost[b]:
            cost[b] = cost[a] + c
tmp = cost[N]
for _ in range(N):
    for a, b, c in edges:
        if cost[a] + c > cost[b]:
            cost[b] = cost[a] + c
if tmp < cost[N]:
    print("inf")
else:
    print(tmp)

-dp = [-float("INF")] * (N + 1) -dp[1] = 0 -edges = [list(map(int, input().split())) for _ in range(M)] +edges = [] +for _ in range(M): +    a, b, c = list(map(int, input().split())) +    edges.append((a, b, c)) +cost = [-float("INF")] * (N + 1) +cost[1] = 0 -while cnt < N: -    cnt += 1 +flag = True +for _ in range(N): -        dp[b] = max(dp[a] + c, dp[b]) -tmp = dp[N] -cnt = 0 -while cnt < N: -    cnt += 1 +        if cost[a] + c > cost[b]: +            cost[b] = cost[a] + c +tmp = cost[N] +for _ in range(N): -        dp[b] = max(dp[a] + c, dp[b]) -if dp[N] > tmp: +        if cost[a] + c > cost[b]: +            cost[b] = cost[a] + c +if tmp < cost[N]: -    print((dp[N])) +    print(tmp)