def main():

    INF = float('inf')

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

    dist = [0] + [INF] * (N-1)

    abc = []

    

    for i in range(M):

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

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

        

    for i in range(N-1):

        for a, b, c in abc:

            if dist[a-1] == INF:

                continue

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

            

    ans = dist[-1]

    negative = [False] * N

    

    for i in range(N):

        for a, b, c in abc:

            if dist[a-1] == INF:

                continue

            elif dist[b-1] > dist[a-1]+c:

                dist[b-1] = dist[a-1]+c

                negative[b-1] = True

            if negative[a-1]:

                negative[b-1] = True

            

    if negative[-1]:

        print('inf')

    else:

        print((-ans))



if __name__ == '__main__':

    main()

    
def main():

    INF = float('inf')

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

    dist = [0] + [INF] * (N-1)

    abc = []

    

    for i in range(M):

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

        abc.append((a-1, b-1, -c))

            

    for a, b, c in abc:

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

        

    ans = dist[-1]

    

    for a, b, c in abc:

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

            

    if ans != dist[-1]:

        print('inf')

    else:

        print((-ans))



if __name__ == '__main__':

    main()
def main():
    INF = float("inf")
    N, M = list(map(int, input().split()))
    dist = [0] + [INF] * (N - 1)
    abc = []
    for i in range(M):
        a, b, c = list(map(int, input().split()))
        abc.append((a, b, -c))
    for i in range(N - 1):
        for a, b, c in abc:
            if dist[a - 1] == INF:
                continue
            dist[b - 1] = min(dist[b - 1], dist[a - 1] + c)
    ans = dist[-1]
    negative = [False] * N
    for i in range(N):
        for a, b, c in abc:
            if dist[a - 1] == INF:
                continue
            elif dist[b - 1] > dist[a - 1] + c:
                dist[b - 1] = dist[a - 1] + c
                negative[b - 1] = True
            if negative[a - 1]:
                negative[b - 1] = True
    if negative[-1]:
        print("inf")
    else:
        print((-ans))


if __name__ == "__main__":
    main()

def main():
    INF = float("inf")
    N, M = list(map(int, input().split()))
    dist = [0] + [INF] * (N - 1)
    abc = []
    for i in range(M):
        a, b, c = list(map(int, input().split()))
        abc.append((a - 1, b - 1, -c))
    for a, b, c in abc:
        dist[b] = min(dist[b], dist[a] + c)
    ans = dist[-1]
    for a, b, c in abc:
        dist[b] = min(dist[b], dist[a] + c)
    if ans != dist[-1]:
        print("inf")
    else:
        print((-ans))


if __name__ == "__main__":
    main()

-        abc.append((a, b, -c)) -    for i in range(N - 1): -        for a, b, c in abc: -            if dist[a - 1] == INF: -                continue -            dist[b - 1] = min(dist[b - 1], dist[a - 1] + c) +        abc.append((a - 1, b - 1, -c)) +    for a, b, c in abc: +        dist[b] = min(dist[b], dist[a] + c) -    negative = [False] * N -    for i in range(N): -        for a, b, c in abc: -            if dist[a - 1] == INF: -                continue -            elif dist[b - 1] > dist[a - 1] + c: -                dist[b - 1] = dist[a - 1] + c -                negative[b - 1] = True -            if negative[a - 1]: -                negative[b - 1] = True -    if negative[-1]: +    for a, b, c in abc: +        dist[b] = min(dist[b], dist[a] + c) +    if ans != dist[-1]: