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

edges = [None] * m



for i in range(m):

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

    edges[i] = (a-1, b-1, -c)



INF = float("inf")

d = [INF] * n

d[0] = 0



for i in range(n-1):

    for f, t, c in edges:

        if d[f] == INF: continue

        d[t] = min(d[t], d[f] + c)



inf_flag = [False] * n



for i in range(n):

    for f, t, c in edges:

        if d[f] == INF: continue

        if inf_flag[f] == True:

            inf_flag[t] = True

        if d[t] > d[f] + c:

            d[t] = d[f] + c

            inf_flag[t] = True



print(("inf" if inf_flag[n-1] else -d[n-1]))

INF = float("inf")



def bellman_ford(edges, n, s):

    d = [0] + [INF] * (n-1)

    for i in range(n):

        for f, t, c in edges:

            if d[f] == INF: continue

            if d[t] > d[f] + c:

                if i == n-1: d[t] = -INF

                else: d[t] = d[f] + c

    for i in range(n):

        for f, t, c in edges:

            if d[f] == INF: continue

            d[t] = min(d[t], d[f] + c)

    return d



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

es = [None] * m

for i in range(m):

    f, t, c = list(map(int, input().split()))

    es[i] = (f-1, t-1, -c)



d = bellman_ford(es, n, 0)

print((-d[n-1]))

n, m = list(map(int, input().split()))
edges = [None] * m
for i in range(m):
    a, b, c = list(map(int, input().split()))
    edges[i] = (a - 1, b - 1, -c)
INF = float("inf")
d = [INF] * n
d[0] = 0
for i in range(n - 1):
    for f, t, c in edges:
        if d[f] == INF:
            continue
        d[t] = min(d[t], d[f] + c)
inf_flag = [False] * n
for i in range(n):
    for f, t, c in edges:
        if d[f] == INF:
            continue
        if inf_flag[f] == True:
            inf_flag[t] = True
        if d[t] > d[f] + c:
            d[t] = d[f] + c
            inf_flag[t] = True
print(("inf" if inf_flag[n - 1] else -d[n - 1]))

INF = float("inf")


def bellman_ford(edges, n, s):
    d = [0] + [INF] * (n - 1)
    for i in range(n):
        for f, t, c in edges:
            if d[f] == INF:
                continue
            if d[t] > d[f] + c:
                if i == n - 1:
                    d[t] = -INF
                else:
                    d[t] = d[f] + c
    for i in range(n):
        for f, t, c in edges:
            if d[f] == INF:
                continue
            d[t] = min(d[t], d[f] + c)
    return d


n, m = list(map(int, input().split()))
es = [None] * m
for i in range(m):
    f, t, c = list(map(int, input().split()))
    es[i] = (f - 1, t - 1, -c)
d = bellman_ford(es, n, 0)
print((-d[n - 1]))

+INF = float("inf") + + +def bellman_ford(edges, n, s): +    d = [0] + [INF] * (n - 1) +    for i in range(n): +        for f, t, c in edges: +            if d[f] == INF: +                continue +            if d[t] > d[f] + c: +                if i == n - 1: +                    d[t] = -INF +                else: +                    d[t] = d[f] + c +    for i in range(n): +        for f, t, c in edges: +            if d[f] == INF: +                continue +            d[t] = min(d[t], d[f] + c) +    return d + + -edges = [None] * m +es = [None] * m -    a, b, c = list(map(int, input().split())) -    edges[i] = (a - 1, b - 1, -c) -INF = float("inf") -d = [INF] * n -d[0] = 0 -for i in range(n - 1): -    for f, t, c in edges: -        if d[f] == INF: -            continue -        d[t] = min(d[t], d[f] + c) -inf_flag = [False] * n -for i in range(n): -    for f, t, c in edges: -        if d[f] == INF: -            continue -        if inf_flag[f] == True: -            inf_flag[t] = True -        if d[t] > d[f] + c: -            d[t] = d[f] + c -            inf_flag[t] = True -print(("inf" if inf_flag[n - 1] else -d[n - 1])) +    f, t, c = list(map(int, input().split())) +    es[i] = (f - 1, t - 1, -c) +d = bellman_ford(es, n, 0) +print((-d[n - 1]))