

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])



dist = [float('inf')] * (N + 1)

dist[1] = 0



for _ in range(N - 1):

    for a, b, c in edges:

        dist[b] = min(dist[b], dist[a] - c)



ans = dist[N]

for a, b, c in edges:

    dist[b] = min(dist[b], dist[a] - c)



if ans == dist[N]:

    print((-ans))

else:

    print('inf')
def main():

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

    edges = []

    

    for _ in range(M):

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

        a -= 1

        b -= 1

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



    d = [float('inf')] * N

    d[0] = 0



    for i in range(N-1):

        for edge in edges:

            d[edge[1]] = min(d[edge[1]], d[edge[0]] - edge[2])



    ans = d[N-1]

    for edge in edges:

        d[edge[1]] = min(d[edge[1]], d[edge[0]] - edge[2])



    if ans == d[N-1]:

        print((-ans))

    else:

        print('inf')





main()
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])
dist = [float("inf")] * (N + 1)
dist[1] = 0
for _ in range(N - 1):
    for a, b, c in edges:
        dist[b] = min(dist[b], dist[a] - c)
ans = dist[N]
for a, b, c in edges:
    dist[b] = min(dist[b], dist[a] - c)
if ans == dist[N]:
    print((-ans))
else:
    print("inf")

def main():
    N, M = list(map(int, input().split()))
    edges = []
    for _ in range(M):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        edges.append([a, b, c])
    d = [float("inf")] * N
    d[0] = 0
    for i in range(N - 1):
        for edge in edges:
            d[edge[1]] = min(d[edge[1]], d[edge[0]] - edge[2])
    ans = d[N - 1]
    for edge in edges:
        d[edge[1]] = min(d[edge[1]], d[edge[0]] - edge[2])
    if ans == d[N - 1]:
        print((-ans))
    else:
        print("inf")


main()

-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]) -dist = [float("inf")] * (N + 1) -dist[1] = 0 -for _ in range(N - 1): -    for a, b, c in edges: -        dist[b] = min(dist[b], dist[a] - c) -ans = dist[N] -for a, b, c in edges: -    dist[b] = min(dist[b], dist[a] - c) -if ans == dist[N]: -    print((-ans)) -else: -    print("inf") +def main(): +    N, M = list(map(int, input().split())) +    edges = [] +    for _ in range(M): +        a, b, c = list(map(int, input().split())) +        a -= 1 +        b -= 1 +        edges.append([a, b, c]) +    d = [float("inf")] * N +    d[0] = 0 +    for i in range(N - 1): +        for edge in edges: +            d[edge[1]] = min(d[edge[1]], d[edge[0]] - edge[2]) +    ans = d[N - 1] +    for edge in edges: +        d[edge[1]] = min(d[edge[1]], d[edge[0]] - edge[2]) +    if ans == d[N - 1]: +        print((-ans)) +    else: +        print("inf") + + +main()