import sys

stdin = sys.stdin



def li(): return [int(x) for x in stdin.readline().split()]

def li_(): return [int(x)-1 for x in stdin.readline().split()]

def lf(): return [float(x) for x in stdin.readline().split()]

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(ns())

def nf(): return float(ns())



n,m = li()



# graph

adj_list = [[] for _ in range(n)]



for _ in range(m):

    a,b,c = li()

    a -= 1

    b -= 1

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



# bellman-ford

INF = -10**15

dist = [INF]*n

dist[0] = 0

for j in range(n+1):

    for i in range(n):

        updated = False

        for cost, nex in adj_list[i]:

            bef = dist[nex]

            dist[nex] = max(dist[nex], dist[i]+cost)

            if bef != dist[nex]:

                updated = True

        

    if j == n-1:

        dis_j1 = dist[n-1]

        

    if j == n:

        dis_j = dist[n-1]

        

if dis_j1 != dis_j:

    print("inf")

else:

    print(dis_j)
import sys

stdin = sys.stdin

 

sys.setrecursionlimit(10**5) 

 

def li(): return list(map(int, stdin.readline().split()))

def li_(): return [int(x)-1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())



n,m = li()



# 隣接リストを作成(key:b, val:a)

edges = []

for _ in range(m):

    ai, bi, ci = li()

    ai -= 1

    bi -= 1

    edges.append((ai, bi, ci))



# ベルマンフォード

dist = [[-10**18]*n for _ in range(2*n+3)]

for i in range(2*n+2):

    dist[i][0] = 0



ans = -10**18

chk = -10**18



for i in range(2*n+2):

    for ai, bi, ci in edges:

        dist[i+1][bi] = max(dist[i+1][bi],

                            dist[i][bi],

                            dist[i][ai] + ci)

    if i == n:

        ans = dist[i][n-1]

        

    elif i == 2*n+1:

        chk = dist[i][n-1]

        

print((ans if ans >= chk else "inf"))
import sys

stdin = sys.stdin


def li():
    return [int(x) for x in stdin.readline().split()]


def li_():
    return [int(x) - 1 for x in stdin.readline().split()]


def lf():
    return [float(x) for x in stdin.readline().split()]


def ls():
    return stdin.readline().split()


def ns():
    return stdin.readline().rstrip()


def lc():
    return list(ns())


def ni():
    return int(ns())


def nf():
    return float(ns())


n, m = li()
# graph
adj_list = [[] for _ in range(n)]
for _ in range(m):
    a, b, c = li()
    a -= 1
    b -= 1
    adj_list[a].append((c, b))
# bellman-ford
INF = -(10**15)
dist = [INF] * n
dist[0] = 0
for j in range(n + 1):
    for i in range(n):
        updated = False
        for cost, nex in adj_list[i]:
            bef = dist[nex]
            dist[nex] = max(dist[nex], dist[i] + cost)
            if bef != dist[nex]:
                updated = True
    if j == n - 1:
        dis_j1 = dist[n - 1]
    if j == n:
        dis_j = dist[n - 1]
if dis_j1 != dis_j:
    print("inf")
else:
    print(dis_j)

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**5)


def li():
    return list(map(int, stdin.readline().split()))


def li_():
    return [int(x) - 1 for x in stdin.readline().split()]


def lf():
    return list(map(float, stdin.readline().split()))


def ls():
    return stdin.readline().split()


def ns():
    return stdin.readline().rstrip()


def lc():
    return list(ns())


def ni():
    return int(stdin.readline())


def nf():
    return float(stdin.readline())


n, m = li()
# 隣接リストを作成(key:b, val:a)
edges = []
for _ in range(m):
    ai, bi, ci = li()
    ai -= 1
    bi -= 1
    edges.append((ai, bi, ci))
# ベルマンフォード
dist = [[-(10**18)] * n for _ in range(2 * n + 3)]
for i in range(2 * n + 2):
    dist[i][0] = 0
ans = -(10**18)
chk = -(10**18)
for i in range(2 * n + 2):
    for ai, bi, ci in edges:
        dist[i + 1][bi] = max(dist[i + 1][bi], dist[i][bi], dist[i][ai] + ci)
    if i == n:
        ans = dist[i][n - 1]
    elif i == 2 * n + 1:
        chk = dist[i][n - 1]
print((ans if ans >= chk else "inf"))

+sys.setrecursionlimit(10**5) -    return [int(x) for x in stdin.readline().split()] +    return list(map(int, stdin.readline().split())) -    return [float(x) for x in stdin.readline().split()] +    return list(map(float, stdin.readline().split())) -    return int(ns()) +    return int(stdin.readline()) -    return float(ns()) +    return float(stdin.readline()) -# graph -adj_list = [[] for _ in range(n)] +# 隣接リストを作成(key:b, val:a) +edges = [] -    a, b, c = li() -    a -= 1 -    b -= 1 -    adj_list[a].append((c, b)) -# bellman-ford -INF = -(10**15) -dist = [INF] * n -dist[0] = 0 -for j in range(n + 1): -    for i in range(n): -        updated = False -        for cost, nex in adj_list[i]: -            bef = dist[nex] -            dist[nex] = max(dist[nex], dist[i] + cost) -            if bef != dist[nex]: -                updated = True -    if j == n - 1: -        dis_j1 = dist[n - 1] -    if j == n: -        dis_j = dist[n - 1] -if dis_j1 != dis_j: -    print("inf") -else: -    print(dis_j) +    ai, bi, ci = li() +    ai -= 1 +    bi -= 1 +    edges.append((ai, bi, ci)) +# ベルマンフォード +dist = [[-(10**18)] * n for _ in range(2 * n + 3)] +for i in range(2 * n + 2): +    dist[i][0] = 0 +ans = -(10**18) +chk = -(10**18) +for i in range(2 * n + 2): +    for ai, bi, ci in edges: +        dist[i + 1][bi] = max(dist[i + 1][bi], dist[i][bi], dist[i][ai] + ci) +    if i == n: +        ans = dist[i][n - 1] +    elif i == 2 * n + 1: +        chk = dist[i][n - 1] +print((ans if ans >= chk else "inf"))