def main():

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

    g = [[] for _ in range(N + 1)]

    d = [float('INF')] * (N + 1)

    d[1] = 0

    for _ in range(M):

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

        c = -c

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

    for i in range(2 * N):

        for x, r in enumerate(g):

            for y, c in r:

                if d[x] != float('INF') and d[y] > d[x] + c:

                    d[y] = d[x] + c

                    if y == N and i > N:

                        print("inf")

                        exit()



    print((-d[-1]))





main()

def main():

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

    g = []

    d = [float('INF')] * (N + 1)

    d[1] = 0

    for _ in range(M):

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

        g.append((a, b, -c))

    for i in range(2 * N):

        for x, y, z in g:

            if d[x] != float('INF') and d[y] > d[x] + z:

                d[y] = d[x] + z

                if y == N and i > N:

                    print("inf")

                    exit()



    print((-d[-1]))





main()

def main():
    N, M = list(map(int, input().split()))
    g = [[] for _ in range(N + 1)]
    d = [float("INF")] * (N + 1)
    d[1] = 0
    for _ in range(M):
        a, b, c = list(map(int, input().split()))
        c = -c
        g[a].append((b, c))
    for i in range(2 * N):
        for x, r in enumerate(g):
            for y, c in r:
                if d[x] != float("INF") and d[y] > d[x] + c:
                    d[y] = d[x] + c
                    if y == N and i > N:
                        print("inf")
                        exit()
    print((-d[-1]))


main()

def main():
    N, M = list(map(int, input().split()))
    g = []
    d = [float("INF")] * (N + 1)
    d[1] = 0
    for _ in range(M):
        a, b, c = list(map(int, input().split()))
        g.append((a, b, -c))
    for i in range(2 * N):
        for x, y, z in g:
            if d[x] != float("INF") and d[y] > d[x] + z:
                d[y] = d[x] + z
                if y == N and i > N:
                    print("inf")
                    exit()
    print((-d[-1]))


main()

-    g = [[] for _ in range(N + 1)] +    g = [] -        c = -c -        g[a].append((b, c)) +        g.append((a, b, -c)) -        for x, r in enumerate(g): -            for y, c in r: -                if d[x] != float("INF") and d[y] > d[x] + c: -                    d[y] = d[x] + c -                    if y == N and i > N: -                        print("inf") -                        exit() +        for x, y, z in g: +            if d[x] != float("INF") and d[y] > d[x] + z: +                d[y] = d[x] + z +                if y == N and i > N: +                    print("inf") +                    exit()