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

a, b, c = [0] * M, [0] * M, [0] * M

d = [-1e20] * N

for i in range(M):

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

    a[i] -= 1

    b[i] -= 1



d[0] = 0

for i in range(N-1):

    for j in range(M):

        d[b[j]] = max((d[b[j]], d[a[j]] + c[j]))



isCycle = False

for i in range(N-1):

    if isCycle:

        break

    for j in range(M):

        if b[j] == N-1 and d[b[j]] < d[a[j]] + c[j]:

            isCycle = True

            break

        d[b[j]] = max((d[b[j]], d[a[j]] + c[j]))

if isCycle:

    print('inf')

else:

    print((d[N-1]))

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

a, b, c = [None] * M, [None] * M, [None] * M

INF = 1e14

d = [-INF] * N

d[0] = 0

for i in range(M):

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

    a[i] -= 1

    b[i] -= 1



for i in range(N):

    for j in range(M):

        if d[a[j]] + c[j] > d[b[j]]:

            d[b[j]] = d[a[j]] + c[j]

ans = d[N-1]

for i in range(N):

    for j in range(M):

        if d[a[j]] + c[j] > d[b[j]]:

            d[b[j]] = d[a[j]] + c[j]

if ans != d[N-1]:

    print('inf')

else:

    print(ans)

N, M = list(map(int, input().split()))
a, b, c = [0] * M, [0] * M, [0] * M
d = [-1e20] * N
for i in range(M):
    a[i], b[i], c[i] = list(map(int, input().split()))
    a[i] -= 1
    b[i] -= 1
d[0] = 0
for i in range(N - 1):
    for j in range(M):
        d[b[j]] = max((d[b[j]], d[a[j]] + c[j]))
isCycle = False
for i in range(N - 1):
    if isCycle:
        break
    for j in range(M):
        if b[j] == N - 1 and d[b[j]] < d[a[j]] + c[j]:
            isCycle = True
            break
        d[b[j]] = max((d[b[j]], d[a[j]] + c[j]))
if isCycle:
    print("inf")
else:
    print((d[N - 1]))

N, M = list(map(int, input().split()))
a, b, c = [None] * M, [None] * M, [None] * M
INF = 1e14
d = [-INF] * N
d[0] = 0
for i in range(M):
    a[i], b[i], c[i] = list(map(int, input().split()))
    a[i] -= 1
    b[i] -= 1
for i in range(N):
    for j in range(M):
        if d[a[j]] + c[j] > d[b[j]]:
            d[b[j]] = d[a[j]] + c[j]
ans = d[N - 1]
for i in range(N):
    for j in range(M):
        if d[a[j]] + c[j] > d[b[j]]:
            d[b[j]] = d[a[j]] + c[j]
if ans != d[N - 1]:
    print("inf")
else:
    print(ans)

-a, b, c = [0] * M, [0] * M, [0] * M -d = [-1e20] * N +a, b, c = [None] * M, [None] * M, [None] * M +INF = 1e14 +d = [-INF] * N +d[0] = 0 -d[0] = 0 -for i in range(N - 1): +for i in range(N): -        d[b[j]] = max((d[b[j]], d[a[j]] + c[j])) -isCycle = False -for i in range(N - 1): -    if isCycle: -        break +        if d[a[j]] + c[j] > d[b[j]]: +            d[b[j]] = d[a[j]] + c[j] +ans = d[N - 1] +for i in range(N): -        if b[j] == N - 1 and d[b[j]] < d[a[j]] + c[j]: -            isCycle = True -            break -        d[b[j]] = max((d[b[j]], d[a[j]] + c[j])) -if isCycle: +        if d[a[j]] + c[j] > d[b[j]]: +            d[b[j]] = d[a[j]] + c[j] +if ans != d[N - 1]: -    print((d[N - 1])) +    print(ans)