import sys



INF = float('inf')



def Bellmanford(n, edges, r): #r: 始点

    d = [INF] * n

    d[r] = 0

    

    for i in range(n):

        for (u, v, c) in edges:

            if d[u] != INF and d[u] + c < d[v]:

                d[v] = d[u] + c

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

                    return 'inf'

    

    return -d[n-1]

    



N, M = list(map(int, sys.stdin.readline().split()))

Edges = [None] * M



for i in range(M):

    ai, bi, ci = list(map(int, sys.stdin.readline().split()))

    Edges[i] = (ai-1, bi-1, -ci)

    

ans = Bellmanford(N, Edges, 0)



print(ans)
import sys

sys.setrecursionlimit(10 ** 9)



import numpy as np

from heapq import heappush, heappop



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

graph = [[] for _ in range(N+1)] # graph[0]は使わない



for _ in range(M):

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

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



def dijkstra(start, c):

    INF = float('inf')

    dist = [-INF] * (N+1) # dist[0]は使わない

    dist[start] = 0

    que = [(start, 0, c)]

    while que:

        place, score, count = heappop(que) # placeは現在地

        if score < dist[place] or count > 3000: # 前来た時より点数が悪いか、無限ループしている場合continue

            continue

        for next_node, weight in graph[place]:

            score2 = score + weight

            if next_node == N and count > 1000: # いくらでも大きくなる場合

                print('inf')

                exit()

            if dist[next_node] < score2: # 点数が良くなるなら、データを更新

                dist[next_node] = score2

                heappush(que, (next_node, score2, count+1))

    return dist



d1 = np.array(dijkstra(1, 0))

print((int(d1[N])))

import sys

INF = float("inf")


def Bellmanford(n, edges, r):  # r: 始点
    d = [INF] * n
    d[r] = 0
    for i in range(n):
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                if i == n - 1 and v == n - 1:
                    return "inf"
    return -d[n - 1]


N, M = list(map(int, sys.stdin.readline().split()))
Edges = [None] * M
for i in range(M):
    ai, bi, ci = list(map(int, sys.stdin.readline().split()))
    Edges[i] = (ai - 1, bi - 1, -ci)
ans = Bellmanford(N, Edges, 0)
print(ans)

import sys

sys.setrecursionlimit(10**9)
import numpy as np
from heapq import heappush, heappop

(
    N,
    M,
) = list(map(int, input().split()))
graph = [[] for _ in range(N + 1)]  # graph[0]は使わない
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    graph[a].append((b, c))


def dijkstra(start, c):
    INF = float("inf")
    dist = [-INF] * (N + 1)  # dist[0]は使わない
    dist[start] = 0
    que = [(start, 0, c)]
    while que:
        place, score, count = heappop(que)  # placeは現在地
        if score < dist[place] or count > 3000:  # 前来た時より点数が悪いか、無限ループしている場合continue
            continue
        for next_node, weight in graph[place]:
            score2 = score + weight
            if next_node == N and count > 1000:  # いくらでも大きくなる場合
                print("inf")
                exit()
            if dist[next_node] < score2:  # 点数が良くなるなら、データを更新
                dist[next_node] = score2
                heappush(que, (next_node, score2, count + 1))
    return dist


d1 = np.array(dijkstra(1, 0))
print((int(d1[N])))

-INF = float("inf") +sys.setrecursionlimit(10**9) +import numpy as np +from heapq import heappush, heappop + +( +    N, +    M, +) = list(map(int, input().split())) +graph = [[] for _ in range(N + 1)]  # graph[0]は使わない +for _ in range(M): +    a, b, c = list(map(int, input().split())) +    graph[a].append((b, c)) -def Bellmanford(n, edges, r):  # r: 始点 -    d = [INF] * n -    d[r] = 0 -    for i in range(n): -        for (u, v, c) in edges: -            if d[u] != INF and d[u] + c < d[v]: -                d[v] = d[u] + c -                if i == n - 1 and v == n - 1: -                    return "inf" -    return -d[n - 1] +def dijkstra(start, c): +    INF = float("inf") +    dist = [-INF] * (N + 1)  # dist[0]は使わない +    dist[start] = 0 +    que = [(start, 0, c)] +    while que: +        place, score, count = heappop(que)  # placeは現在地 +        if score < dist[place] or count > 3000:  # 前来た時より点数が悪いか、無限ループしている場合continue +            continue +        for next_node, weight in graph[place]: +            score2 = score + weight +            if next_node == N and count > 1000:  # いくらでも大きくなる場合 +                print("inf") +                exit() +            if dist[next_node] < score2:  # 点数が良くなるなら、データを更新 +                dist[next_node] = score2 +                heappush(que, (next_node, score2, count + 1)) +    return dist -N, M = list(map(int, sys.stdin.readline().split())) -Edges = [None] * M -for i in range(M): -    ai, bi, ci = list(map(int, sys.stdin.readline().split())) -    Edges[i] = (ai - 1, bi - 1, -ci) -ans = Bellmanford(N, Edges, 0) -print(ans) +d1 = np.array(dijkstra(1, 0)) +print((int(d1[N])))