CodeEff/ECCO huggingface dataset:
# Original solution
def bell(edges, n):
    count = 0
    dist = [-10000000000000000 for i in range(n)]
    dist[0] = 0

    changed = True

    while changed:
        count  += 1
        if count == 500000:
            print('inf')
            exit()
        changed = False
        for edge in edges:
            if dist[edge[1]] < dist[edge[0]] + edge[2]:
                changed = True
            dist[edge[1]] = max(dist[edge[0]] + edge[2], dist[edge[1]])
                
    return dist


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

res = bell(edges, n)

print((res[n-1]))

# Optimized solution
N, M = list(map(int, input().split()))
Edges = []
for i in range(M):
    a, b, c = list(map(int, input().split()))
    a, b = a - 1, b - 1
    c = -c
    Edges.append([a, b, c])
 
dist = [float('inf')] * N
dist[0] = 0
 
for i in range(N):
    for fr, to, cost in Edges:
        if (dist[fr] != float('inf')) and (dist[to] > dist[fr] + cost):
            dist[to] = dist[fr] + cost
            if (i == N - 1) & (to == N - 1):
                print('inf')
                exit()
 
print((-dist[-1]))
# Original solution
N, M = list(map(int, input().split()))
Edges = []
for i in range(M):
    a, b, c = list(map(int, input().split()))
    a, b = a - 1, b - 1
    c = -c
    Edges.append([a, b, c])
 
dist = [float('inf')] * N
dist[0] = 0
 
for i in range(N):
    for fr, to, cost in Edges:
        if (dist[fr] != float('inf')) and (dist[to] > dist[fr] + cost):
            dist[to] = dist[fr] + cost
            if (i == N - 1) & (to == N - 1):
                print('inf')
                exit()
 
print((-dist[-1]))

# Optimized solution
def bell(edges, n):
    count = 0
    dist = [float('inf') for i in range(n)]
    dist[0] = 0

 
    for i in range(n):
        for edge in edges:
            if dist[edge[1]] > dist[edge[0]] + edge[2] and edge[0] != float('inf'):
                dist[edge[1]] = dist[edge[0]] + edge[2]
                if (i == n - 1) & (edge[1] == n - 1):
                    print('inf')
                    exit()
                
    return dist
 
 
n,m = list(map(int,input().split()))
edges = []
for _ in range(m):
    a, b, c = (int(x) for x in input().split())
    edges.append([a-1, b-1, -c])
 
res = bell(edges, n)
 
print((-res[n-1]))
# Original solution
class BellmanFord:
    def __init__(self, graph, num_v, start_point):
        self.num_v = num_v
        self.graph = graph
        self.start_point = start_point


    def execute(self):
        dist = [float("inf") for _ in range(self.num_v)]
        dist[self.start_point] = 0
        negative = [False for _ in range(self.num_v)]
        for i in range(self.num_v - 1):
            for src in range(self.num_v):
                for dest, cost in list(self.graph[src].items()):
                    if dist[dest] > dist[src] + cost:
                        dist[dest] = dist[src] + cost
        for i in range(self.num_v):
            for src in range(self.num_v):
                for dest, cost in list(self.graph[src].items()):
                    if dist[dest] > dist[src] + cost:
                        dist[dest] = dist[src] + cost
                        negative[dest] = True
                    if negative[src]:
                        negative[dest] = True
        return dist, negative


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

for i in range(m):
    a, b, c = list(map(int, input().split()))
    graph[a-1][b-1] = -c
bellman = BellmanFord(graph, n, 0)
result, negative = bellman.execute()

if negative[-1]:
    print("inf")
else:
    print((-result[-1]))


# Optimized solution
class BellmanFord:
    def __init__(self, graph, num_v, start_point):
        self.num_v = num_v
        self.graph = graph
        self.start_point = start_point


    def execute(self):
        dist = [float("inf") for _ in range(self.num_v)]
        dist[self.start_point] = 0
        negative = [False for _ in range(self.num_v)]
        for i in range(self.num_v - 1):
            for src, dest, cost in self.graph:
                if dist[dest] > dist[src] + cost:
                    dist[dest] = dist[src] + cost
        for i in range(self.num_v):
            for src, dest, cost in self.graph:
                if dist[dest] > dist[src] + cost:
                    dist[dest] = dist[src] + cost
                    negative[dest] = True
                if negative[src]:
                    negative[dest] = True
        return dist, negative


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

for i in range(m):
    a, b, c = list(map(int, input().split()))
    graph.append([a-1, b-1, -c])
bellman = BellmanFord(graph, n, 0)
result, negative = bellman.execute()

if negative[-1]:
    print("inf")
else:
    print((-result[-1]))
# Original solution
N,M = list(map(int,input().split()))

from collections import deque
ls = [deque([]) for _ in range(N)]

for i in range(M):
    a,b,c = list(map(int,input().split()))
    a,b = a-1,b-1
    ls[a].append([b,c])
cost = [-(10**10)*N]*N
cost[0] = 0

for i in range(N):
    update = False
    q = [deque(m for m in l) for l in ls]
    for j in range(N):
        if cost[j] != -(10**10)*N:
            while q[j]:
                b,c = q[j].pop()
                if cost[b] < cost[j] + c:
                    cost[b] = cost[j] + c
                    update = True
    if i == 0:
        Max = cost[N-1]
    elif i < N-1:
        Max = max(Max,cost[N-1])

if update == True and Max < cost[N-1]:
    print('inf')
else:
    print(Max)


# Optimized solution
N,M = list(map(int,input().split()))
abc = []
for _ in range(M):
    abc.append(list(map(int,input().split())))

cost = [-(10**10)*N]*N
cost[0] = 0

for i in range(N):
    update = False
    for a,b,c in abc:
        a,b = a-1,b-1
        if cost[a] != -(10**10)*N:
            if cost[b] < cost[a] + c:
                cost[b] = cost[a] + c
                update = True
    if i == 0:
        Max = cost[N-1]
    elif i < N-1:
        Max = max(Max,cost[N-1])


if update == True and Max < cost[N-1]:
    print('inf')
else:
    print(Max)
# Original solution
N,M = list(map(int,input().split()))
abc = []
for _ in range(M):
    abc.append(list(map(int,input().split())))

cost = [-float('inf')]*N
cost[0] = 0

for i in range(N):
    update = False
    for a,b,c in abc:
        a,b = a-1,b-1
        if cost[a] != -(10**10)*N:
            if cost[b] < cost[a] + c:
                cost[b] = cost[a] + c
                update = True
    if i == 0:
        Max = cost[N-1]
    elif i < N-1:
        Max = max(Max,cost[N-1])


if update == True and Max < cost[N-1]:
    print('inf')
else:
    print(Max)


# Optimized solution
N,M = list(map(int,input().split()))
abc = []
for _ in range(M):
    abc.append(list(map(int,input().split())))

cost = [-float('inf')]*N
cost[0] = 0

for i in range(2):
    for a,b,c in abc:
        a,b = a-1,b-1
        cost[b] = max(cost[b], cost[a] + c)

    if i == 0:
        ans = cost[N-1]
    else:
        Max = cost[N-1]


if ans != Max:
    print('inf')
else:
    print(ans)
# Original solution
from collections import defaultdict
N, M, *L = list(map(int, open(0).read().split()))
dic = defaultdict(list)
rdic = defaultdict(list)
nin = [0]*N
Els = []
for a,b,c in zip(*[iter(L)]*3):
  dic[a-1] += [b-1]
  rdic[b-1] += [a-1]
  nin[b-1] += 1
  Els += [(a-1,b-1,-c)]

To = [False]*N
From = [False]*N
q = [0]
To[0] = True
while q:
  p = q.pop()
  for e in dic[p]:
    if To[e]==False:
      To[e] = True
      q += [e]
q = [N-1]
From[N-1] = True
while q:
  p = q.pop()
  for e in rdic[p]:
    if From[e]==False:
      From[e] = True
      q += [e]

ok = [False]*N
for i  in range(N):
  ok[i] = To[i]&From[i]

cnt = 0
dist = [float('inf')]*N
dist[0] = 0
cnt = 0
flag = False
while True:
  update = True
  for a,b,c in Els:
    if not(ok[a] and ok[b]):
      continue
    if dist[a]!=float('inf') and dist[b]>dist[a]+c:
      dist[b] = dist[a]+c
      update = False
  if update:
    break
  cnt += 1
  if cnt>2*N:
    flag = True
    break

if flag:
  print('inf')
elif dist[N-1]==float('inf'):
  print('inf')
else:
  print((-dist[N-1]))

# Optimized solution
from collections import defaultdict
N, M, *L = list(map(int, open(0).read().split()))
dic = defaultdict(list)
rdic = defaultdict(list)
nin = [0]*N
Els = []
for a,b,c in zip(*[iter(L)]*3):
  dic[a-1] += [b-1]
  rdic[b-1] += [a-1]
  nin[b-1] += 1
  Els += [(a-1,b-1,-c)]

To = [False]*N
From = [False]*N
q = [0]
To[0] = True
while q:
  p = q.pop()
  for e in dic[p]:
    if To[e]==False:
      To[e] = True
      q += [e]
q = [N-1]
From[N-1] = True
while q:
  p = q.pop()
  for e in rdic[p]:
    if From[e]==False:
      From[e] = True
      q += [e]

ok = [False]*N
for i  in range(N):
  ok[i] = To[i]&From[i]

cnt = 0
dist = [float('inf')]*N
dist[0] = 0
cnt = 0
flag = False
while True:
  update = True
  for a,b,c in Els:
    if not(ok[a] and ok[b]):
      continue
    if dist[a]!=float('inf') and dist[b]>dist[a]+c:
      dist[b] = dist[a]+c
      update = False
  if update:
    break
  cnt += 1
  if cnt>N:
    flag = True
    break

if flag:
  print('inf')
else:
  print((-dist[N-1]))
# Original solution
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
  return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(eval(input()))
def II(): return list(map(int, input().split()))
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return list(map(list,list(zip(*read_all))))

#################

def BF(E,s,n):
  inf=float("inf")
  d=[inf for _ in range(n)]
  d[s]=0
  for i in range(n+1):
    for e in E:
      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 'loop'
  return d

N,M = II()
E = []
for i in range(M):
  a,b,c = II()
  E.append([a,b,-c])

d = BF(E,0,N)

if d=='loop':
  print('inf')
else:
  print((-d[N-1]))

# Optimized solution
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
  return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(eval(input()))
def II(): return list(map(int, input().split()))
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return list(map(list,list(zip(*read_all))))

#################

def BF(E,s,n):
  inf=float("inf")
  d=[inf for _ in range(n)]
  d[s]=0
  for i in range(n+1):
    for e in E:
      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 'loop'
  return d

def main():
  N,M = II()
  E = []
  for _ in range(M):
    a,b,c = II()
    E.append([a,b,-c])

  d = BF(E,0,N)

  if d=='loop':
    print('inf')
  else:
    print((-d[N-1]))

if __name__ == '__main__':
  main()
# Original solution
n,m=list(map(int,input().split()))
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

loop=set()
d=[-10**15 for _ in [0]*n]
d[0]=0
q=[[0,1]]
s=set()
l=[]
while q:
    item,depth=q.pop()
    if depth<=len(s):
        for _ in range(len(s)-depth+1):
            rmv=l.pop()
            s.remove(rmv)
    l.append(item)
    s.add(item)
    for i,dist in g[item]:
        if d[i]<d[item]+dist:
            if i in s:
                loop.add(i)
                continue
            d[i]=d[item]+dist
            q.append([i,depth+1])
  
c=[False for _ in [0]*n]
for x in loop:
    if c[x]==True:
        continue
    q=[x]
    c[x]=True
    while q:
        item=q.pop()
        for i,j in g[item]:
            if c[i]==False:
                c[i]=True
                q.append(i)
if c[n-1]==True:
    print("inf")
else:
    print((d[n-1]))

# Optimized solution
n,m=list(map(int,input().split()))
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

dist=[-10**15 for _ in [0]*n]
dist[0]=0
a,b=-10**15,-10**15

for _ in range(n):
    for p in range(n):
        for i,j in g[p]:
            dist[i]=max(dist[i],dist[p]+j)
    a,b=b,dist[n-1]

if a==b:
    print(a)
else:
    print("inf")
# Original solution
ai = lambda: list(map(int, input().split()))

n, m = ai()

from collections import defaultdict as dd

edge = dd(list)
for _ in range(m):
    a, b, c = ai()
    edge[a - 1].append([b - 1, -c])

dist = [float('inf')] * n
dist[0] = 0
vs = {0}
i = 0
while vs:
    cur_v = vs.pop()
    for v, c in edge[cur_v]:
        if dist[v] > dist[cur_v] + c:
            dist[v] = dist[cur_v] + c
            vs.add(v)
            if i > n and v == n - 1:
                print('inf')
                exit()
    i += 1

print((-dist[-1]))

# Optimized solution
ai = lambda: list(map(int, input().split()))

n, m = ai()

from collections import defaultdict as dd

edge = dd(list)
for _ in range(m):
    a, b, c = ai()
    edge[a - 1].append([b - 1, -c])


dist = [float('inf')] * n
dist[0] = 0
vs = {0}
i = 0
while vs:
    cur_v = vs.pop()
    for v, c in edge[cur_v]:
        if dist[v] > dist[cur_v] + c:
            dist[v] = dist[cur_v] + c
            vs.add(v)
            if i >= n-1 and v == n-1:
                print('inf')
                exit()
    i += 1
    if i > n*2:
        break
print((-dist[-1]))
# Original solution
inf = float('inf')

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

e = []
for _ in range(m):
    s, t, c = list(map(int, input().split()))
    s -= 1
    t -= 1
    c *= -1
    e.append((s, t, c))

dist = [inf] * n
dist[0] = 0
ans = None
for cnt in range(n * 2):
    for s, t, c in e:
        if dist[s] != inf and dist[t] > dist[s] + c:
            dist[t] = dist[s] + c
            update = True
    if cnt == n - 1:
        ans = -dist[n - 1]
if ans != -dist[n - 1]:
    print('inf')
else:
    print(ans)

# 「ベルマンフォード法」の pythonのコード
# (https://juppy.hatenablog.com/entry/2018/10/30/%E6%9C%80%E7%9F%AD%E7%B5%8C%E8%B7%AF%E9%96%A2%E9%80%A3_python_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0)
#
# Bellman Fordは負辺があってもかまわない場合の単一始点全点間最短距離を求め，同時に負閉路の存在を検出するアルゴリズムである．
#
# これは動的計画法に基づくアルゴリズムで，k 回目の更新によって始点から k ステップ以下で進む場合の最短距離が計算される．
# もし n 回目にもまだ更新があるのならば，経路はどこかに負の閉路を含んでいるので，
# その頂点への経路には負閉路が存在するとして距離を負の無限大に設定する．
# (http://www.prefield.com/algorithm/graph/bellman_ford.html)
#
# 通常の Bellman-Ford 法における負閉路検出は、後者の負閉路に対して「負閉路あり」と判定してしまうことに注意。それを防ぐためには、
# 本来 Bellman-Ford は N-1 回のイテレーションで終わるので N 回目以降にも更新が行われたら負閉路ありとしていたところを
# N 回目以降にも頂点 N への最短路が更新されたら、「1 から N までの間に負閉路あり」
# と判定すればいい。この場合、ループは 2N 回程度回せば確実。
# (http://drken1215.hatenablog.com/entry/2019/02/16/075900)


# Optimized solution
def Bellman_Ford(s, g, inf=1 << 60):
    # https://tjkendev.github.io/procon-library/python/graph/bellman-ford.html
    N = len(g)
    dist = [inf] * N
    dist[s] = 0

    for _ in range(N):
        not_updated = True
        for v in range(N):
            for u, c in g[v]:
                if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue
                dist[u] = dist[v] + c
                not_updated = False
        if not_updated: break

    else:
        # 負閉路が存在する
        ret = dist[N - 1]
        for v in range(N):
            for u, c in g[v]:
                if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue
                dist[u] = dist[v] + c

        if ret == dist[N - 1]:
            return -ret
        else:
            return 'inf'

    return -dist[N - 1]


def main():
    import sys
    input = sys.stdin.readline

    sys.setrecursionlimit(10 ** 7)

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

    g = tuple(set() for _ in range(N))
    for _ in range(M):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        g[a].add((b, -c))

    ans = Bellman_Ford(s=0, g=g)
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
# -*- coding: utf-8 -*-

"""
・ベルマンフォード
"""

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

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

edges = [None] * M
for i in range(M):
    a, b, c = list(map(int, input().split()))
    # 0-indexed
    # コストの正負を逆転させれば最短経路問題として処理できる
    edges[i] = (a-1, b-1, -c)

def bellman_ford(N: int, edges: list, start: int) -> list:
    # 頂点[ある始点からの最短距離]
    # (経路自体を知りたい時はここに前の頂点も持たせる)
    verts = [float('inf')] * N
    verts[start] = 0
    # 各辺によるコストの置き換えを頂点数N-1回繰り返す
    for i in range(N-1):
        for src, dest, cost in edges:
            verts[dest] = min(verts[src] + cost, verts[dest])
    # 無限に減らせる場所がないか確認
    for src, dest, cost in edges:
        if verts[src] + cost < verts[dest]:
            verts[dest] = verts[src] + cost
            if dest == N-1:
                # 頂点Nがそれに該当していたら空リストを返却
                return []
    # 問題なければ頂点リストを返却
    return verts

verts = bellman_ford(N, edges, 0)
if not verts:
    print('inf')
else:
    # 正負を戻して出力
    print((-verts[N-1]))


# Optimized solution
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc061/editorial.pdf
・ベルマンフォード
・負の閉路があっても、そこに頂点Nが含まれなければ今回はOK
　って点に気付けなかったー。
"""

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

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

edges = [None] * M
for i in range(M):
    a, b, c = list(map(int, input().split()))
    # 0-indexed
    # コストの正負を逆転させれば最短経路問題として処理できる
    edges[i] = (a-1, b-1, -c)

def bellman_ford(N: int, edges: list, start: int) -> list:
    # 頂点[ある始点からの最短距離]
    # (経路自体を知りたい時はここに前の頂点も持たせる)
    verts = [float('inf')] * N
    verts[start] = 0
    # 各辺によるコストの置き換えを頂点数N-1回繰り返す
    for i in range(N-1):
        for src, dest, cost in edges:
            if verts[dest] > verts[src] + cost:
                verts[dest] = verts[src] + cost
    # 無限に減らせる場所がないか確認
    for i in range(N):
        for src, dest, cost in edges:
            if verts[dest] > verts[src] + cost:
                verts[dest] = verts[src] + cost
                if dest == N-1:
                    # 頂点Nがそれに該当していたら空リストを返却
                    return []
    # 問題なければ頂点リストを返却
    return verts

verts = bellman_ford(N, edges, 0)
if not verts:
    print('inf')
else:
    # 正負を戻して出力
    print((-verts[N-1]))
# Original solution
import sys 

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

for _ in range(M):
    a, b, c = list(map(int, input().split()))
    a_list.append(a)
    b_list.append(b)
    c_list.append(-c)

inf = sys.maxsize
dist = [inf for _ in range(N)]
dist[0] = 0

for _ in range(N-1):
    for i in range(M):
        if dist[a_list[i]-1] == inf:
            continue
        if dist[b_list[i]-1] > dist[a_list[i]-1] + c_list[i]:
            dist[b_list[i]-1] = dist[a_list[i]-1] + c_list[i]

ans = dist[N-1]
negative = [False for _ in range(N)]

for _ in range(N):
    for i in range(M):
        if dist[a_list[i]-1] == inf:
            continue
        if dist[b_list[i]-1] > dist[a_list[i]-1] + c_list[i]:
            dist[b_list[i]-1] = dist[a_list[i]-1] + c_list[i]
            negative[b_list[i]-1] = True
        if negative[a_list[i]-1]:
            negative[b_list[i]-1] = True

if negative[N-1]:
    print('inf')
else:
    print((str(-ans)))



# Optimized solution
import sys 

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

for _ in range(M):
    a, b, c = list(map(int, input().split()))
    a_list.append(a)
    b_list.append(b)
    c_list.append(-c)

inf = sys.maxsize
dist = [inf] * N
dist[0] = 0

for loop in range(N):
    for i in range(M):
        if dist[a_list[i]-1] == inf:
            continue
        if dist[b_list[i]-1] > dist[a_list[i]-1] + c_list[i]:
            dist[b_list[i]-1] = dist[a_list[i]-1] + c_list[i]
            if loop == N - 1 and b_list[i] == N:
                print('inf')
                sys.exit()

print((-dist[N-1]))
# Original solution
# -*- coding: utf-8 -*-
inf = 10**50
n,m = list(map(int, input().split()))

ea = []
eb = []
cost = []

for _ in range(m):
    a,b,c = list(map(int, input().split()))
    a -= 1
    b -= 1
    ea.append(a)
    eb.append(b)
    cost.append(-c)

d = [inf for _ in range(n)]
d[0] = 0
for _ in range(n):
    update = False
    for i in range(m):
        a = ea[i]
        b = eb[i]
        c = cost[i]
        if d[a]!=inf and d[b]>d[a]+c:
            d[b] = d[a]+c
            update = True
    if not update:
        break

ans = d[n-1]
negative = [False for _ in range(n)]
for _ in range(n):
    for i in range(m):
        a = ea[i]
        b = eb[i]
        c = cost[i]
        if d[a]!=inf and d[b]>d[a]+c:
            d[b] = d[a]+c
            negative[b] = True
        if negative[a]:
            negative[b] = True
# print(d)
if negative[n-1]:
    print("inf")
else:
    print((-ans))


# Optimized solution
# -*- coding: utf-8 -*-
inf = 10**50
n,m = list(map(int, input().split()))

ea = []
eb = []
cost = []

for _ in range(m):
    a,b,c = list(map(int, input().split()))
    a -= 1
    b -= 1
    ea.append(a)
    eb.append(b)
    cost.append(-c)

d = [inf for _ in range(n)]
d[0] = 0
for _ in range(n):
    update = False
    for i in range(m):
        a = ea[i]
        b = eb[i]
        c = cost[i]
        if d[a]!=inf and d[b]>d[a]+c:
            d[b] = d[a]+c
            update = True
    if not update:
        break

ans = d[n-1]
negative = [False for _ in range(n)]
for _ in range(n):
    update = False
    for i in range(m):
        a = ea[i]
        b = eb[i]
        c = cost[i]
        if d[a]!=inf and d[b]>d[a]+c:
            d[b] = d[a]+c
            if not negative[b]:
                update = True
            negative[b] = True
        if negative[a] and not negative[b]:
            negative[b] = True
            update = True
    if not update:
        break
# print(d)
if negative[n-1]:
    print("inf")
else:
    print((-ans))