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

inf=float("inf")

l=[tuple(map(int,input().split())) for i in range(m)]

 

d=[inf]*n

d[0]=0



for i in range(n):

  for a,b,c in l:

    a,b,c=a-1,b-1,-c

    if d[a]!=inf and d[b]>d[a]+c:

      d[b]=d[a]+c

      if i==n-1 and b==n-1:

        print("inf")

        exit()

print((-d[-1]))
n,m=list(map(int,input().split()))

es=[list(map(int,input().split())) for _ in range(m)]

inf=float("inf")

d=[-inf]*(n+1)

d[1]=0



def bellman_ford():

  for i in range(n):

    isUpdated=False

    for e_from,e_to,cost in es:

      if d[e_to]<d[e_from]+cost:

        d[e_to]=d[e_from]+cost

        isUpdated=True

        if i==n-1 and e_to==n:return inf

    if not isUpdated:

      break

  return d[n]



print((bellman_ford()))
n, m = list(map(int, input().split()))
inf = float("inf")
l = [tuple(map(int, input().split())) for i in range(m)]
d = [inf] * n
d[0] = 0
for i in range(n):
    for a, b, c in l:
        a, b, c = a - 1, b - 1, -c
        if d[a] != inf and d[b] > d[a] + c:
            d[b] = d[a] + c
            if i == n - 1 and b == n - 1:
                print("inf")
                exit()
print((-d[-1]))

n, m = list(map(int, input().split()))
es = [list(map(int, input().split())) for _ in range(m)]
inf = float("inf")
d = [-inf] * (n + 1)
d[1] = 0


def bellman_ford():
    for i in range(n):
        isUpdated = False
        for e_from, e_to, cost in es:
            if d[e_to] < d[e_from] + cost:
                d[e_to] = d[e_from] + cost
                isUpdated = True
                if i == n - 1 and e_to == n:
                    return inf
        if not isUpdated:
            break
    return d[n]


print((bellman_ford()))

+es = [list(map(int, input().split())) for _ in range(m)] -l = [tuple(map(int, input().split())) for i in range(m)] -d = [inf] * n -d[0] = 0 -for i in range(n): -    for a, b, c in l: -        a, b, c = a - 1, b - 1, -c -        if d[a] != inf and d[b] > d[a] + c: -            d[b] = d[a] + c -            if i == n - 1 and b == n - 1: -                print("inf") -                exit() -print((-d[-1])) +d = [-inf] * (n + 1) +d[1] = 0 + + +def bellman_ford(): +    for i in range(n): +        isUpdated = False +        for e_from, e_to, cost in es: +            if d[e_to] < d[e_from] + cost: +                d[e_to] = d[e_from] + cost +                isUpdated = True +                if i == n - 1 and e_to == n: +                    return inf +        if not isUpdated: +            break +    return d[n] + + +print((bellman_ford()))