# -*- coding: utf-8 -*-

inf = 10**15

n,m = list(map(int, input().split()))

edge = []

for _ in range(m):

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

    a -= 1

    b -= 1

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



d = [inf for _ in range(n)]

d[0] = 0

for _ in range(n):

    update = False

    for i in range(m):

        a,b,c = edge[i]

        if d[a]<inf:

            if d[b]<inf:

                if d[b]<d[a]+c:

                    d[b] = d[a]+c

                    update = True

            else:

                update = True

                d[b] = d[a] + c

    if not update:

        break



ans = d[n-1]

updated = [False for _ in range(n)]

for _ in range(n):

    update = False

    for i in range(m):

        a,b,c = edge[i]

        if d[a]<inf:

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

                d[b] = d[a] + c

                if not updated[b]:

                    update = True

                    updated[b] = True

        if updated[a] and not updated[b]:

            update = True

            updated[b] = True

    if not update:

        break



if updated[n-1]:

    print("inf")

else:

    print(ans)

# -*- coding: utf-8 -*-

def bellmanFord(e,n,s):

    inf = 10**18

    d = [inf]*n

    d[s] = 0



    loop = False

    for i in range(n):

        updated = False

        for v in range(n):

            for u,c in e[v]:

                if d[v]!=inf and d[u]>d[v]+c:

                    d[u] = d[v]+c

                    updated = True

                    if i==n-1 and u==n-1:

                        loop = True

        if not updated:

            break

    return d,loop





n,m = list(map(int, input().split()))

e = [[] for _ in range(n)]

for _ in range(m):

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

    a -= 1

    b -= 1

    e[a].append((b,-c))



d,loop = bellmanFord(e,n,0)

if loop:

    print("inf")

else:

    print((-d[n-1]))
# -*- coding: utf-8 -*-
inf = 10**15
n, m = list(map(int, input().split()))
edge = []
for _ in range(m):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    edge.append((a, b, c))
d = [inf for _ in range(n)]
d[0] = 0
for _ in range(n):
    update = False
    for i in range(m):
        a, b, c = edge[i]
        if d[a] < inf:
            if d[b] < inf:
                if d[b] < d[a] + c:
                    d[b] = d[a] + c
                    update = True
            else:
                update = True
                d[b] = d[a] + c
    if not update:
        break
ans = d[n - 1]
updated = [False for _ in range(n)]
for _ in range(n):
    update = False
    for i in range(m):
        a, b, c = edge[i]
        if d[a] < inf:
            if d[a] + c > d[b]:
                d[b] = d[a] + c
                if not updated[b]:
                    update = True
                    updated[b] = True
        if updated[a] and not updated[b]:
            update = True
            updated[b] = True
    if not update:
        break
if updated[n - 1]:
    print("inf")
else:
    print(ans)

# -*- coding: utf-8 -*-
def bellmanFord(e, n, s):
    inf = 10**18
    d = [inf] * n
    d[s] = 0
    loop = False
    for i in range(n):
        updated = False
        for v in range(n):
            for u, c in e[v]:
                if d[v] != inf and d[u] > d[v] + c:
                    d[u] = d[v] + c
                    updated = True
                    if i == n - 1 and u == n - 1:
                        loop = True
        if not updated:
            break
    return d, loop


n, m = list(map(int, input().split()))
e = [[] for _ in range(n)]
for _ in range(m):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    e[a].append((b, -c))
d, loop = bellmanFord(e, n, 0)
if loop:
    print("inf")
else:
    print((-d[n - 1]))

-inf = 10**15 +def bellmanFord(e, n, s): +    inf = 10**18 +    d = [inf] * n +    d[s] = 0 +    loop = False +    for i in range(n): +        updated = False +        for v in range(n): +            for u, c in e[v]: +                if d[v] != inf and d[u] > d[v] + c: +                    d[u] = d[v] + c +                    updated = True +                    if i == n - 1 and u == n - 1: +                        loop = True +        if not updated: +            break +    return d, loop + + -edge = [] +e = [[] for _ in range(n)] -    edge.append((a, b, c)) -d = [inf for _ in range(n)] -d[0] = 0 -for _ in range(n): -    update = False -    for i in range(m): -        a, b, c = edge[i] -        if d[a] < inf: -            if d[b] < inf: -                if d[b] < d[a] + c: -                    d[b] = d[a] + c -                    update = True -            else: -                update = True -                d[b] = d[a] + c -    if not update: -        break -ans = d[n - 1] -updated = [False for _ in range(n)] -for _ in range(n): -    update = False -    for i in range(m): -        a, b, c = edge[i] -        if d[a] < inf: -            if d[a] + c > d[b]: -                d[b] = d[a] + c -                if not updated[b]: -                    update = True -                    updated[b] = True -        if updated[a] and not updated[b]: -            update = True -            updated[b] = True -    if not update: -        break -if updated[n - 1]: +    e[a].append((b, -c)) +d, loop = bellmanFord(e, n, 0) +if loop: -    print(ans) +    print((-d[n - 1]))