import sys

from collections import Counter



sys.setrecursionlimit(10**7)

 

inf = 1<<100

 

def solve():

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

    edges = [None]*M

    Adj = [[] for i in range(N)]

 

    for i in range(M):

        ui, vi, ci = list(map(int, sys.stdin.readline().split()))

        ui, vi = ui - 1, vi - 1

        edges[i] = (ui, vi, -ci)

        Adj[ui].append(vi)



    visitable = [False]*N



    dfs(N, M, Adj, visitable, 0)



    reachable = [False]*N

    reachable[0] = True

    reachable[N - 1] = True



    for u in range(1, N - 1):

        visited = [False]*N



        dfs(N, M, Adj, visited, u)



        if visited[N - 1]:

            reachable[u] = True

 

    ans = Bellmanford(N, M, edges, visitable, reachable)

 

    if ans is not None:

        print((-ans))

    else:

        print('inf')



def dfs(N, M, Adj, visitable, u):

    visitable[u] = True



    for v in Adj[u]:

        if not visitable[v]:

            dfs(N, M, Adj, visitable, v)



def Bellmanford(N, M, edges, visitable, reachable):

    dist = [inf]*N

    dist[0] = 0

    flag = True



    cnt = 0

 

    for i in range(N):

        flag = False



        for (u, v, c) in edges:

            if dist[u] != inf and dist[v] > dist[u] + c:

                dist[v] = dist[u] + c



                if visitable[v] and reachable[v]:

                    flag = True



        # print(dist)



        if not flag:

            break



        if flag and i == N - 1:

            return None



    return dist[N - 1]

 

if __name__ == '__main__':

    solve()
import sys



inf = 1<<60



def solve():

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

    edges = [None] * M



    for i in range(M):

        ai, bi, ci = list(map(int, sys.stdin.readline().split()))

        ai, bi = ai - 1, bi - 1

        edges[i] = (ai, bi, -ci)



    ans = BellmanFord(N, M, edges)



    if ans is None:

        print('inf')

    else:

        print((-ans))



def BellmanFord(N, M, edges):

    d = [inf] * N

    d[0] = 0



    for i in range(N - 1):

        for (u, v, c) in edges:

            if d[u] + c < d[v]:

                d[v] = d[u] + c



    for i in range(N):

        for (u, v, c) in edges:

            if d[u] + c < d[v]:

                if v == N - 1:

                    return None



                d[v] = d[u] + c



    return d[N - 1]



if __name__ == '__main__':

    solve()
import sys
from collections import Counter

sys.setrecursionlimit(10**7)
inf = 1 << 100


def solve():
    N, M = list(map(int, input().split()))
    edges = [None] * M
    Adj = [[] for i in range(N)]
    for i in range(M):
        ui, vi, ci = list(map(int, sys.stdin.readline().split()))
        ui, vi = ui - 1, vi - 1
        edges[i] = (ui, vi, -ci)
        Adj[ui].append(vi)
    visitable = [False] * N
    dfs(N, M, Adj, visitable, 0)
    reachable = [False] * N
    reachable[0] = True
    reachable[N - 1] = True
    for u in range(1, N - 1):
        visited = [False] * N
        dfs(N, M, Adj, visited, u)
        if visited[N - 1]:
            reachable[u] = True
    ans = Bellmanford(N, M, edges, visitable, reachable)
    if ans is not None:
        print((-ans))
    else:
        print("inf")


def dfs(N, M, Adj, visitable, u):
    visitable[u] = True
    for v in Adj[u]:
        if not visitable[v]:
            dfs(N, M, Adj, visitable, v)


def Bellmanford(N, M, edges, visitable, reachable):
    dist = [inf] * N
    dist[0] = 0
    flag = True
    cnt = 0
    for i in range(N):
        flag = False
        for (u, v, c) in edges:
            if dist[u] != inf and dist[v] > dist[u] + c:
                dist[v] = dist[u] + c
                if visitable[v] and reachable[v]:
                    flag = True
        # print(dist)
        if not flag:
            break
        if flag and i == N - 1:
            return None
    return dist[N - 1]


if __name__ == "__main__":
    solve()

import sys

inf = 1 << 60


def solve():
    N, M = list(map(int, input().split()))
    edges = [None] * M
    for i in range(M):
        ai, bi, ci = list(map(int, sys.stdin.readline().split()))
        ai, bi = ai - 1, bi - 1
        edges[i] = (ai, bi, -ci)
    ans = BellmanFord(N, M, edges)
    if ans is None:
        print("inf")
    else:
        print((-ans))


def BellmanFord(N, M, edges):
    d = [inf] * N
    d[0] = 0
    for i in range(N - 1):
        for (u, v, c) in edges:
            if d[u] + c < d[v]:
                d[v] = d[u] + c
    for i in range(N):
        for (u, v, c) in edges:
            if d[u] + c < d[v]:
                if v == N - 1:
                    return None
                d[v] = d[u] + c
    return d[N - 1]


if __name__ == "__main__":
    solve()

-from collections import Counter -sys.setrecursionlimit(10**7) -inf = 1 << 100 +inf = 1 << 60 -    Adj = [[] for i in range(N)] -        ui, vi, ci = list(map(int, sys.stdin.readline().split())) -        ui, vi = ui - 1, vi - 1 -        edges[i] = (ui, vi, -ci) -        Adj[ui].append(vi) -    visitable = [False] * N -    dfs(N, M, Adj, visitable, 0) -    reachable = [False] * N -    reachable[0] = True -    reachable[N - 1] = True -    for u in range(1, N - 1): -        visited = [False] * N -        dfs(N, M, Adj, visited, u) -        if visited[N - 1]: -            reachable[u] = True -    ans = Bellmanford(N, M, edges, visitable, reachable) -    if ans is not None: +        ai, bi, ci = list(map(int, sys.stdin.readline().split())) +        ai, bi = ai - 1, bi - 1 +        edges[i] = (ai, bi, -ci) +    ans = BellmanFord(N, M, edges) +    if ans is None: +        print("inf") +    else: -    else: -        print("inf") -def dfs(N, M, Adj, visitable, u): -    visitable[u] = True -    for v in Adj[u]: -        if not visitable[v]: -            dfs(N, M, Adj, visitable, v) - - -def Bellmanford(N, M, edges, visitable, reachable): -    dist = [inf] * N -    dist[0] = 0 -    flag = True -    cnt = 0 +def BellmanFord(N, M, edges): +    d = [inf] * N +    d[0] = 0 +    for i in range(N - 1): +        for (u, v, c) in edges: +            if d[u] + c < d[v]: +                d[v] = d[u] + c -        flag = False -            if dist[u] != inf and dist[v] > dist[u] + c: -                dist[v] = dist[u] + c -                if visitable[v] and reachable[v]: -                    flag = True -        # print(dist) -        if not flag: -            break -        if flag and i == N - 1: -            return None -    return dist[N - 1] +            if d[u] + c < d[v]: +                if v == N - 1: +                    return None +                d[v] = d[u] + c +    return d[N - 1]