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

edges = []

for i in range(M):

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

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

edges.sort()



def bellmanford(n, edges, start):

    INF = float('inf')

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

    dist[start] = 0



    for i in range(n):

        for (pre, ne, weight) in edges:

            if dist[pre] != -INF and dist[pre] + weight > dist[ne]:

                dist[ne] = dist[pre] + weight

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

                    return 'inf'

    return dist[n]



answer = bellmanford(N, edges, 1)

print(answer)
# D - Score Attack

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 > 2000: # 前来た時より点数が悪いか、無限ループしている場合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])))
N, M = list(map(int, input().split()))
edges = []
for i in range(M):
    a, b, c = list(map(int, input().split()))
    edges.append((a, b, c))
edges.sort()


def bellmanford(n, edges, start):
    INF = float("inf")
    dist = [-INF] * (n + 1)  # dist[0]は使わない
    dist[start] = 0
    for i in range(n):
        for (pre, ne, weight) in edges:
            if dist[pre] != -INF and dist[pre] + weight > dist[ne]:
                dist[ne] = dist[pre] + weight
                if i == n - 1 and ne == n:
                    return "inf"
    return dist[n]


answer = bellmanford(N, edges, 1)
print(answer)

# D - Score Attack
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 > 2000:  # 前来た時より点数が悪いか、無限ループしている場合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])))

-N, M = list(map(int, input().split())) -edges = [] -for i in range(M): +# D - Score Attack +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): -    edges.append((a, b, c)) -edges.sort() +    graph[a].append((b, c)) -def bellmanford(n, edges, start): +def dijkstra(start, c): -    dist = [-INF] * (n + 1)  # dist[0]は使わない +    dist = [-INF] * (N + 1)  # dist[0]は使わない -    for i in range(n): -        for (pre, ne, weight) in edges: -            if dist[pre] != -INF and dist[pre] + weight > dist[ne]: -                dist[ne] = dist[pre] + weight -                if i == n - 1 and ne == n: -                    return "inf" -    return dist[n] +    que = [(start, 0, c)] +    while que: +        place, score, count = heappop(que)  # placeは現在地 +        if score < dist[place] or count > 2000:  # 前来た時より点数が悪いか、無限ループしている場合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 -answer = bellmanford(N, edges, 1) -print(answer) +d1 = np.array(dijkstra(1, 0)) +print((int(d1[N])))