#https://qiita.com/chun1182/items/ddf2b6cba932b2bb0d4e

def BF(p,n,s):

    inf=float("inf")

    d=[inf for i in range(n)]

    d[s-1]=0

    for i in range(n+1):

        for e in p:

            if e[0]!=inf and d[e[1]-1]>d[e[0]-1]+e[2]:

                d[e[1]-1] = d[e[0]-1] + e[2]

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

        if i==n and t!=d[-1]:

            return [0,'inf']

    return list([-x for x in d])



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

g=[]

for _ in range(m):

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

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

print((BF(g,n,1)[-1]))
import sys

sys.setrecursionlimit(10**9)



def BF(edges,n,s):

    inf=float("inf")

    d=[inf for i in range(n+1)]

    d[s]=0

    update=True

    for i in range(n+1):

      update=False

      for v,u,cost in edges:

        if cand[v]!=1 or cand[u]!=1:

          continue

        if d[v]!=inf and d[u]>d[v]+cost:

          d[u]=d[v]+cost

          update=True

      if update==False:

        break

      if i==n:

        return inf

    return -d[-1]



def DFS_1toN(v):

  for u in to[v]:

    if toflag[u]==0:

      toflag[u]=1

      DFS_1toN(u)

      

def DFS_Nto1(v):

  for u in ot[v]:

    if otflag[u]==0:

      otflag[u]=1

      DFS_Nto1(u)

    

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

g=[]

to=[[] for _ in range(n+1)]

ot=[[] for _ in range(n+1)]

for _ in range(m):

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

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

  to[a].append(b)

  ot[b].append(a)

toflag=[0]*(n+1)

toflag[1]=1

DFS_1toN(1)

otflag=[0]*(n+1)

otflag[n]=1

DFS_Nto1(n)

cand=[0]*(n+1)

for i in range(1,n+1):

  cand[i]=toflag[i]*otflag[i]

ans=BF(g,n,1)

if ans==float('inf'):

  print('inf')

else:

  print(ans)
# https://qiita.com/chun1182/items/ddf2b6cba932b2bb0d4e
def BF(p, n, s):
    inf = float("inf")
    d = [inf for i in range(n)]
    d[s - 1] = 0
    for i in range(n + 1):
        for e in p:
            if e[0] != inf and d[e[1] - 1] > d[e[0] - 1] + e[2]:
                d[e[1] - 1] = d[e[0] - 1] + e[2]
        if i == n - 1:
            t = d[-1]
        if i == n and t != d[-1]:
            return [0, "inf"]
    return list([-x for x in d])


n, m = list(map(int, input().split()))
g = []
for _ in range(m):
    a, b, c = list(map(int, input().split()))
    g.append([a, b, -c])
print((BF(g, n, 1)[-1]))

import sys

sys.setrecursionlimit(10**9)


def BF(edges, n, s):
    inf = float("inf")
    d = [inf for i in range(n + 1)]
    d[s] = 0
    update = True
    for i in range(n + 1):
        update = False
        for v, u, cost in edges:
            if cand[v] != 1 or cand[u] != 1:
                continue
            if d[v] != inf and d[u] > d[v] + cost:
                d[u] = d[v] + cost
                update = True
        if update == False:
            break
        if i == n:
            return inf
    return -d[-1]


def DFS_1toN(v):
    for u in to[v]:
        if toflag[u] == 0:
            toflag[u] = 1
            DFS_1toN(u)


def DFS_Nto1(v):
    for u in ot[v]:
        if otflag[u] == 0:
            otflag[u] = 1
            DFS_Nto1(u)


n, m = list(map(int, input().split()))
g = []
to = [[] for _ in range(n + 1)]
ot = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b, c = list(map(int, input().split()))
    g.append([a, b, -c])
    to[a].append(b)
    ot[b].append(a)
toflag = [0] * (n + 1)
toflag[1] = 1
DFS_1toN(1)
otflag = [0] * (n + 1)
otflag[n] = 1
DFS_Nto1(n)
cand = [0] * (n + 1)
for i in range(1, n + 1):
    cand[i] = toflag[i] * otflag[i]
ans = BF(g, n, 1)
if ans == float("inf"):
    print("inf")
else:
    print(ans)

-# https://qiita.com/chun1182/items/ddf2b6cba932b2bb0d4e -def BF(p, n, s): +import sys + +sys.setrecursionlimit(10**9) + + +def BF(edges, n, s): -    d = [inf for i in range(n)] -    d[s - 1] = 0 +    d = [inf for i in range(n + 1)] +    d[s] = 0 +    update = True -        for e in p: -            if e[0] != inf and d[e[1] - 1] > d[e[0] - 1] + e[2]: -                d[e[1] - 1] = d[e[0] - 1] + e[2] -        if i == n - 1: -            t = d[-1] -        if i == n and t != d[-1]: -            return [0, "inf"] -    return list([-x for x in d]) +        update = False +        for v, u, cost in edges: +            if cand[v] != 1 or cand[u] != 1: +                continue +            if d[v] != inf and d[u] > d[v] + cost: +                d[u] = d[v] + cost +                update = True +        if update == False: +            break +        if i == n: +            return inf +    return -d[-1] + + +def DFS_1toN(v): +    for u in to[v]: +        if toflag[u] == 0: +            toflag[u] = 1 +            DFS_1toN(u) + + +def DFS_Nto1(v): +    for u in ot[v]: +        if otflag[u] == 0: +            otflag[u] = 1 +            DFS_Nto1(u) +to = [[] for _ in range(n + 1)] +ot = [[] for _ in range(n + 1)] -print((BF(g, n, 1)[-1])) +    to[a].append(b) +    ot[b].append(a) +toflag = [0] * (n + 1) +toflag[1] = 1 +DFS_1toN(1) +otflag = [0] * (n + 1) +otflag[n] = 1 +DFS_Nto1(n) +cand = [0] * (n + 1) +for i in range(1, n + 1): +    cand[i] = toflag[i] * otflag[i] +ans = BF(g, n, 1) +if ans == float("inf"): +    print("inf") +else: +    print(ans)