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

Edges = []

for i in range(M):

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

    a, b = a - 1, b - 1

    c = -c

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

 

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

dist[0] = 0

 

for i in range(N):

    for fr, to, cost in Edges:

        if (dist[fr] != float('inf')) and (dist[to] > dist[fr] + cost):

            dist[to] = dist[fr] + cost

            if (i == N - 1) & (to == N - 1):

                print('inf')

                exit()

 

print((-dist[-1]))
def bell(edges, n):

    count = 0

    dist = [float('inf') for i in range(n)]

    dist[0] = 0



 

    for i in range(n):

        for edge in edges:

            if dist[edge[1]] > dist[edge[0]] + edge[2] and edge[0] != float('inf'):

                dist[edge[1]] = dist[edge[0]] + edge[2]

                if (i == n - 1) & (edge[1] == n - 1):

                    print('inf')

                    exit()

                

    return dist

 

 

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

edges = []

for _ in range(m):

    a, b, c = (int(x) for x in input().split())

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

 

res = bell(edges, n)

 

print((-res[n-1]))
N, M = list(map(int, input().split()))
Edges = []
for i in range(M):
    a, b, c = list(map(int, input().split()))
    a, b = a - 1, b - 1
    c = -c
    Edges.append([a, b, c])
dist = [float("inf")] * N
dist[0] = 0
for i in range(N):
    for fr, to, cost in Edges:
        if (dist[fr] != float("inf")) and (dist[to] > dist[fr] + cost):
            dist[to] = dist[fr] + cost
            if (i == N - 1) & (to == N - 1):
                print("inf")
                exit()
print((-dist[-1]))

def bell(edges, n):
    count = 0
    dist = [float("inf") for i in range(n)]
    dist[0] = 0
    for i in range(n):
        for edge in edges:
            if dist[edge[1]] > dist[edge[0]] + edge[2] and edge[0] != float("inf"):
                dist[edge[1]] = dist[edge[0]] + edge[2]
                if (i == n - 1) & (edge[1] == n - 1):
                    print("inf")
                    exit()
    return dist


n, m = list(map(int, input().split()))
edges = []
for _ in range(m):
    a, b, c = (int(x) for x in input().split())
    edges.append([a - 1, b - 1, -c])
res = bell(edges, n)
print((-res[n - 1]))

-N, M = list(map(int, input().split())) -Edges = [] -for i in range(M): -    a, b, c = list(map(int, input().split())) -    a, b = a - 1, b - 1 -    c = -c -    Edges.append([a, b, c]) -dist = [float("inf")] * N -dist[0] = 0 -for i in range(N): -    for fr, to, cost in Edges: -        if (dist[fr] != float("inf")) and (dist[to] > dist[fr] + cost): -            dist[to] = dist[fr] + cost -            if (i == N - 1) & (to == N - 1): -                print("inf") -                exit() -print((-dist[-1])) +def bell(edges, n): +    count = 0 +    dist = [float("inf") for i in range(n)] +    dist[0] = 0 +    for i in range(n): +        for edge in edges: +            if dist[edge[1]] > dist[edge[0]] + edge[2] and edge[0] != float("inf"): +                dist[edge[1]] = dist[edge[0]] + edge[2] +                if (i == n - 1) & (edge[1] == n - 1): +                    print("inf") +                    exit() +    return dist + + +n, m = list(map(int, input().split())) +edges = [] +for _ in range(m): +    a, b, c = (int(x) for x in input().split()) +    edges.append([a - 1, b - 1, -c]) +res = bell(edges, n) +print((-res[n - 1]))