#import numpy as np

#from numpy import*

#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall

#from scipy.sparse import csr_matrix



from collections import* #defaultdict Counter deque appendleft

from fractions import gcd

from functools import* #reduce

from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate

from operator import mul,itemgetter

from bisect import* #bisect_left bisect_right

from heapq import* #heapify heappop heappushpop

from math import factorial,pi

from copy import deepcopy

import sys

sys.setrecursionlimit(10**8)

input=sys.stdin.readline  #危険！基本オフにしろ！



def BELLMANFORD(point,d,n):

    cost       = {node:-float("inf")for node in range(1,n+1)}

    preference = {node:None         for node in range(1,n+1)}      #最適路のこと 

    cost[point]= 0

    for i in range(n-1):                                  #経路の長さは最大n-1であるため

        for now,lis in list(d.copy().items()):

            for nex,c in lis:

                if cost[nex]<cost[now]+c:

                    cost[nex]=cost[now]+c

                    preference[nex]=now

 

    negative=[0]*n                                        #負閉路の長さは最大nであるため

    

    for i in range(n):                  #閉路判定

        for now,lis in list(d.copy().items()):

            for nex,c in lis:

                if negative[now-1]==1:

                    negative[nex-1]=1

                if cost[nex]<cost[now]+c:

                    cost[nex]=cost[now]+c

                    preference[nex]=now

                    negative[now-1]=1

 

    return cost,negative





def main():

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

    d=defaultdict(list)

    for i in range(m):

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

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

    x,y=(BELLMANFORD(1,d,n))

    if y[n-1]>0:

        print("inf")

    else:

        print((x[n]))





if __name__ == '__main__':

    main()

import sys

input=sys.stdin.readline  #危険！基本オフにしろ！



def BELLMANFORD(point,d,n):

    cost       = [-float("inf")for node in range(n+1)]

    preference = [None         for node in range(n+1)]      #最適路のこと 

    cost[point]= 0

    for i in range(n-1):                                  #経路の長さは最大n-1であるため

        for now,lis in list(d.items()):

            for nex,c in lis:

                if cost[nex]<cost[now]+c:

                    cost[nex]=cost[now]+c

                    preference[nex]=now

 

    negative=[0]*n                                        #負閉路の長さは最大nであるため

    

    for i in range(n):                  #閉路判定

        for now,lis in list(d.items()):

            for nex,c in lis:

                if negative[now-1]==1:

                    negative[nex-1]=1

                if cost[nex]<cost[now]+c:

                    cost[nex]=cost[now]+c

                    preference[nex]=now

                    negative[now-1]=1

 

    return cost,negative





def main():

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

    

    d={}

    for s in range(m):

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

        if a in d:

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

        else:

            d[a]=[(b,c)]

    

    x,y=(BELLMANFORD(1,d,n))

    

    if y[n-1]>0:

        print("inf")

    else:

        print((x[n]))





if __name__ == '__main__':

    main()

# import numpy as np
# from numpy import*
# from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
# from scipy.sparse import csr_matrix
from collections import *  # defaultdict Counter deque appendleft
from fractions import gcd
from functools import *  # reduce
from itertools import *  # permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul, itemgetter
from bisect import *  # bisect_left bisect_right
from heapq import *  # heapify heappop heappushpop
from math import factorial, pi
from copy import deepcopy
import sys

sys.setrecursionlimit(10**8)
input = sys.stdin.readline  # 危険！基本オフにしろ！


def BELLMANFORD(point, d, n):
    cost = {node: -float("inf") for node in range(1, n + 1)}
    preference = {node: None for node in range(1, n + 1)}  # 最適路のこと
    cost[point] = 0
    for i in range(n - 1):  # 経路の長さは最大n-1であるため
        for now, lis in list(d.copy().items()):
            for nex, c in lis:
                if cost[nex] < cost[now] + c:
                    cost[nex] = cost[now] + c
                    preference[nex] = now
    negative = [0] * n  # 負閉路の長さは最大nであるため
    for i in range(n):  # 閉路判定
        for now, lis in list(d.copy().items()):
            for nex, c in lis:
                if negative[now - 1] == 1:
                    negative[nex - 1] = 1
                if cost[nex] < cost[now] + c:
                    cost[nex] = cost[now] + c
                    preference[nex] = now
                    negative[now - 1] = 1
    return cost, negative


def main():
    n, m = list(map(int, input().split()))
    d = defaultdict(list)
    for i in range(m):
        a, b, c = list(map(int, input().split()))
        d[a].append([b, c])
    x, y = BELLMANFORD(1, d, n)
    if y[n - 1] > 0:
        print("inf")
    else:
        print((x[n]))


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline  # 危険！基本オフにしろ！


def BELLMANFORD(point, d, n):
    cost = [-float("inf") for node in range(n + 1)]
    preference = [None for node in range(n + 1)]  # 最適路のこと
    cost[point] = 0
    for i in range(n - 1):  # 経路の長さは最大n-1であるため
        for now, lis in list(d.items()):
            for nex, c in lis:
                if cost[nex] < cost[now] + c:
                    cost[nex] = cost[now] + c
                    preference[nex] = now
    negative = [0] * n  # 負閉路の長さは最大nであるため
    for i in range(n):  # 閉路判定
        for now, lis in list(d.items()):
            for nex, c in lis:
                if negative[now - 1] == 1:
                    negative[nex - 1] = 1
                if cost[nex] < cost[now] + c:
                    cost[nex] = cost[now] + c
                    preference[nex] = now
                    negative[now - 1] = 1
    return cost, negative


def main():
    n, m = list(map(int, input().split()))
    d = {}
    for s in range(m):
        a, b, c = list(map(int, input().split()))
        if a in d:
            d[a].append((b, c))
        else:
            d[a] = [(b, c)]
    x, y = BELLMANFORD(1, d, n)
    if y[n - 1] > 0:
        print("inf")
    else:
        print((x[n]))


if __name__ == "__main__":
    main()

-# import numpy as np -# from numpy import* -# from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall -# from scipy.sparse import csr_matrix -from collections import *  # defaultdict Counter deque appendleft -from fractions import gcd -from functools import *  # reduce -from itertools import *  # permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate -from operator import mul, itemgetter -from bisect import *  # bisect_left bisect_right -from heapq import *  # heapify heappop heappushpop -from math import factorial, pi -from copy import deepcopy -sys.setrecursionlimit(10**8) -    cost = {node: -float("inf") for node in range(1, n + 1)} -    preference = {node: None for node in range(1, n + 1)}  # 最適路のこと +    cost = [-float("inf") for node in range(n + 1)] +    preference = [None for node in range(n + 1)]  # 最適路のこと -        for now, lis in list(d.copy().items()): +        for now, lis in list(d.items()): -        for now, lis in list(d.copy().items()): +        for now, lis in list(d.items()): -    d = defaultdict(list) -    for i in range(m): +    d = {} +    for s in range(m): -        d[a].append([b, c]) +        if a in d: +            d[a].append((b, c)) +        else: +            d[a] = [(b, c)]