inf = float('inf')



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

info = []

for _ in range(M):

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

    a -= 1; b -= 1

    info.append((a,b,c))

 

dist = [-inf for _ in range(N)]

dist[0] = 0

for i in range(N):

    for v,nv,w in info:

        if dist[nv] < dist[v] + w:

            dist[nv] = dist[v] + w

            if i == N-1 and nv == N-1:

                print("inf")

                exit()

ans = dist[N-1]

print(ans)
inf = float('inf')



# distの初期化: dist = [inf for _ in range(N)]; dist[start] = 0

# True - >正常に更新, False -> 負閉路有り

def bellmanford(dist,edges,N):

    for i in range(N):

        for v ,nv, w in edges:

            if dist[nv] > dist[v] + w:

                dist[nv] = dist[v] + w

                # 頂点数Nなら更新は高々N-1回で済む

                # N回目に更新を行うなら負閉路があるということ

                if i == N-1 and nv == N-1:

                    return False

    return True



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

info = []

for _ in range(M):

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

    a -= 1; b -= 1; c = -c

    info.append((a,b,c))

 

dist = [inf for _ in range(N)]

dist[0] = 0



flag = bellmanford(dist,info,N)

ans = -dist[N-1] if flag is True else "inf"

print(ans)
inf = float("inf")
N, M = list(map(int, input().split()))
info = []
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    info.append((a, b, c))
dist = [-inf for _ in range(N)]
dist[0] = 0
for i in range(N):
    for v, nv, w in info:
        if dist[nv] < dist[v] + w:
            dist[nv] = dist[v] + w
            if i == N - 1 and nv == N - 1:
                print("inf")
                exit()
ans = dist[N - 1]
print(ans)

inf = float("inf")
# distの初期化: dist = [inf for _ in range(N)]; dist[start] = 0
# True - >正常に更新, False -> 負閉路有り
def bellmanford(dist, edges, N):
    for i in range(N):
        for v, nv, w in edges:
            if dist[nv] > dist[v] + w:
                dist[nv] = dist[v] + w
                # 頂点数Nなら更新は高々N-1回で済む
                # N回目に更新を行うなら負閉路があるということ
                if i == N - 1 and nv == N - 1:
                    return False
    return True


N, M = list(map(int, input().split()))
info = []
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    c = -c
    info.append((a, b, c))
dist = [inf for _ in range(N)]
dist[0] = 0
flag = bellmanford(dist, info, N)
ans = -dist[N - 1] if flag is True else "inf"
print(ans)

+# distの初期化: dist = [inf for _ in range(N)]; dist[start] = 0 +# True - >正常に更新, False -> 負閉路有り +def bellmanford(dist, edges, N): +    for i in range(N): +        for v, nv, w in edges: +            if dist[nv] > dist[v] + w: +                dist[nv] = dist[v] + w +                # 頂点数Nなら更新は高々N-1回で済む +                # N回目に更新を行うなら負閉路があるということ +                if i == N - 1 and nv == N - 1: +                    return False +    return True + + +    c = -c -dist = [-inf for _ in range(N)] +dist = [inf for _ in range(N)] -for i in range(N): -    for v, nv, w in info: -        if dist[nv] < dist[v] + w: -            dist[nv] = dist[v] + w -            if i == N - 1 and nv == N - 1: -                print("inf") -                exit() -ans = dist[N - 1] +flag = bellmanford(dist, info, N) +ans = -dist[N - 1] if flag is True else "inf"