import sys

input = sys.stdin.readline



def main():

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



    graph = []

    for _ in range(M):

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

        graph.append([a-1, b-1, -d])



    INF = int(1E18)



    D = [INF for _ in range(N)]

    D[0] = 0



    for c in range(N-1):

        update = False

        for i, j, d in graph:

            if D[i] != INF and D[j] > D[i] + d:

                D[j] = D[i] + d

                update = True

        if not update:

            break



    negative = [False for _ in range(N)]

    for c in range(N):

        update = False

        for i, j, d in graph:

            if D[i] != INF and D[j] > D[i] + d:

                update = True

                D[j] = D[i] + d

                negative[j] = True

        if not update:

            break

    if negative[N-1]:

        print('inf')

    else:

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



if __name__ == "__main__":

    main()
import sys

input = sys.stdin.readline



INF = 10**17



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

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





def bfs(graph, start):

    checked = [False]*N

    checked[start] = True

    q = [start]

    while q:

        qq = []

        for p in q:

            for np in graph[p]:

                if not checked[np]:

                    qq.append(np)

                    checked[np] = True

        q = qq

    return checked



graph1 = [[] for _ in range(N)]

graph2 = [[] for _ in range(N)]

for a, b, e in Edges:

    graph1[a-1].append(b-1)

    graph2[b-1].append(a-1)



checked1 = bfs(graph1, 0)

checked2 = bfs(graph2, N-1)



n_Edges = []

for a, b, e in Edges:

    if checked1[a-1] and checked2[b-1]:

        n_Edges.append((a, b, e))



D = [INF]*N

D[0] = 0

ok = True

for i in range(N):

    update = False

    for a, b, c in n_Edges:

        if D[a-1] != INF and D[b-1] > D[a-1] - c:

            D[b-1] = D[a-1] - c

            update = True

    if i==N-1 and update:

        ok = False



if not ok:

    print('inf')

else:

    print((-D[N-1]))
import sys

input = sys.stdin.readline


def main():
    N, M = list(map(int, input().split()))
    graph = []
    for _ in range(M):
        a, b, d = list(map(int, input().split()))
        graph.append([a - 1, b - 1, -d])
    INF = int(1e18)
    D = [INF for _ in range(N)]
    D[0] = 0
    for c in range(N - 1):
        update = False
        for i, j, d in graph:
            if D[i] != INF and D[j] > D[i] + d:
                D[j] = D[i] + d
                update = True
        if not update:
            break
    negative = [False for _ in range(N)]
    for c in range(N):
        update = False
        for i, j, d in graph:
            if D[i] != INF and D[j] > D[i] + d:
                update = True
                D[j] = D[i] + d
                negative[j] = True
        if not update:
            break
    if negative[N - 1]:
        print("inf")
    else:
        print((-D[N - 1]))


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline
INF = 10**17
N, M = list(map(int, input().split()))
Edges = [list(map(int, input().split())) for _ in range(M)]


def bfs(graph, start):
    checked = [False] * N
    checked[start] = True
    q = [start]
    while q:
        qq = []
        for p in q:
            for np in graph[p]:
                if not checked[np]:
                    qq.append(np)
                    checked[np] = True
        q = qq
    return checked


graph1 = [[] for _ in range(N)]
graph2 = [[] for _ in range(N)]
for a, b, e in Edges:
    graph1[a - 1].append(b - 1)
    graph2[b - 1].append(a - 1)
checked1 = bfs(graph1, 0)
checked2 = bfs(graph2, N - 1)
n_Edges = []
for a, b, e in Edges:
    if checked1[a - 1] and checked2[b - 1]:
        n_Edges.append((a, b, e))
D = [INF] * N
D[0] = 0
ok = True
for i in range(N):
    update = False
    for a, b, c in n_Edges:
        if D[a - 1] != INF and D[b - 1] > D[a - 1] - c:
            D[b - 1] = D[a - 1] - c
            update = True
    if i == N - 1 and update:
        ok = False
if not ok:
    print("inf")
else:
    print((-D[N - 1]))

+INF = 10**17 +N, M = list(map(int, input().split())) +Edges = [list(map(int, input().split())) for _ in range(M)] -def main(): -    N, M = list(map(int, input().split())) -    graph = [] -    for _ in range(M): -        a, b, d = list(map(int, input().split())) -        graph.append([a - 1, b - 1, -d]) -    INF = int(1e18) -    D = [INF for _ in range(N)] -    D[0] = 0 -    for c in range(N - 1): -        update = False -        for i, j, d in graph: -            if D[i] != INF and D[j] > D[i] + d: -                D[j] = D[i] + d -                update = True -        if not update: -            break -    negative = [False for _ in range(N)] -    for c in range(N): -        update = False -        for i, j, d in graph: -            if D[i] != INF and D[j] > D[i] + d: -                update = True -                D[j] = D[i] + d -                negative[j] = True -        if not update: -            break -    if negative[N - 1]: -        print("inf") -    else: -        print((-D[N - 1])) +def bfs(graph, start): +    checked = [False] * N +    checked[start] = True +    q = [start] +    while q: +        qq = [] +        for p in q: +            for np in graph[p]: +                if not checked[np]: +                    qq.append(np) +                    checked[np] = True +        q = qq +    return checked -if __name__ == "__main__": -    main() +graph1 = [[] for _ in range(N)] +graph2 = [[] for _ in range(N)] +for a, b, e in Edges: +    graph1[a - 1].append(b - 1) +    graph2[b - 1].append(a - 1) +checked1 = bfs(graph1, 0) +checked2 = bfs(graph2, N - 1) +n_Edges = [] +for a, b, e in Edges: +    if checked1[a - 1] and checked2[b - 1]: +        n_Edges.append((a, b, e)) +D = [INF] * N +D[0] = 0 +ok = True +for i in range(N): +    update = False +    for a, b, c in n_Edges: +        if D[a - 1] != INF and D[b - 1] > D[a - 1] - c: +            D[b - 1] = D[a - 1] - c +            update = True +    if i == N - 1 and update: +        ok = False +if not ok: +    print("inf") +else: +    print((-D[N - 1]))