inf = float('inf')

# ベルマンフォード法

# 計算量O(VE) V:頂点数, E:辺の数

# [引数]   n:頂点数, edges:辺集合, start:始点, end:終点

# [返り値] dist:startからの最短距離, exists_negative_cycle: 負閉路が存在するかどうか

def bellmanford(n : int, edges : list, start : int, goal : int) -> (list, bool):

    dist = [inf] * n

    dist[start] = 0

    exist_negative_cycle = True



    # 負閉路を含まないとき、頂点数nなら更新は高々n-1回で済む

    for _ in range(N-1):

        for v, nv, w in edges:

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

                dist[nv] = dist[v] + w





    # (1)グラフに負閉路が含まれるときの検出

    # N回目で更新があったとき、グラフは負閉路を含む

    # for v, nv, w in edges:

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

    #         is_cycle = False



    # (2)startとendのパスに負閉路が含まれるときの検出

    is_updated = [False] * n

    for _ in range(N):

        for v, nv, w in edges:

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

                dist[nv] = dist[v] + w

                is_updated[nv] = True

            if is_updated[v] is True:

                is_updated[nv] = True



    exist_negative_cycle = is_updated[goal]



    return dist, exist_negative_cycle



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

edges = []

for _ in range(M):

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

    a -= 1; b -= 1

    edges.append((a, b, -c))



dist, exist_negative_cycle = bellmanford(N, edges, 0, N-1)



if exist_negative_cycle is True:

    ans = "inf"

else:

    ans = -dist[N-1]



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

# ベルマンフォード法 計算量(VE)

# [引数]: 隣接リスト, 始点, 終点

class Bellmanford:

    def __init__(self, to : list, start : int, goal : int):

        self.N = len(to)

        self.to = [s[:] for s in to]

        self.start = start

        self.goal = goal

        self.dist = [inf] * self.N

        self.dist[start] = 0

        self.exists_negative_cycle = False

        self.exists_negative_cycle_stog = False

        self.is_updated = [False] * self.N

    

    # self.distを更新

    def update(self) -> None:

        for _ in range(self.N - 1):

            for v, s in enumerate(self.to):

                if not s: continue

                for nv, w in s:

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

                        self.dist[nv] = self.dist[v] + w

    

    # グラフの負閉路検出

    def detection(self) -> bool:

        for v, s in enumerate(self.to):

            if not s: continue

            for nv, w in s:

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

                    self.dist[nv] = self.dist[v] + w

                    self.exists_negative_cycle = True

        return self.exists_negative_cycle

    

    # スタートからゴールまでのパスの負閉路検出

    def detection_stog(self) -> bool:

        for _ in range(self.N):

            for v, s in enumerate(self.to):

                if not s: continue

                for nv, w in s:

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

                        self.dist[nv] = self.dist[v] + w

                        self.is_updated[nv] = True

                    if self.is_updated[v] is True:

                        self.is_updated[nv] = True

        self.exists_negative_cycle_stog = self.is_updated[self.goal]

        return self.exists_negative_cycle_stog



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

to = [[] for _ in range(N)]

for _ in range(M):

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

    a -= 1; b -= 1

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



BF = Bellmanford(to, 0, N-1)

BF.update()



if BF.detection_stog():

    ans = "inf"

else:

    ans = -BF.dist[N-1]



print(ans)
inf = float("inf")
# ベルマンフォード法
# 計算量O(VE) V:頂点数, E:辺の数
# [引数]   n:頂点数, edges:辺集合, start:始点, end:終点
# [返り値] dist:startからの最短距離, exists_negative_cycle: 負閉路が存在するかどうか
def bellmanford(n: int, edges: list, start: int, goal: int) -> (list, bool):
    dist = [inf] * n
    dist[start] = 0
    exist_negative_cycle = True
    # 負閉路を含まないとき、頂点数nなら更新は高々n-1回で済む
    for _ in range(N - 1):
        for v, nv, w in edges:
            if dist[nv] > dist[v] + w:
                dist[nv] = dist[v] + w
    # (1)グラフに負閉路が含まれるときの検出
    # N回目で更新があったとき、グラフは負閉路を含む
    # for v, nv, w in edges:
    #     if dist[nv] > dist[v] + w:
    #         is_cycle = False
    # (2)startとendのパスに負閉路が含まれるときの検出
    is_updated = [False] * n
    for _ in range(N):
        for v, nv, w in edges:
            if dist[nv] > dist[v] + w:
                dist[nv] = dist[v] + w
                is_updated[nv] = True
            if is_updated[v] is True:
                is_updated[nv] = True
    exist_negative_cycle = is_updated[goal]
    return dist, exist_negative_cycle


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

inf = float("inf")
# ベルマンフォード法 計算量(VE)
# [引数]: 隣接リスト, 始点, 終点
class Bellmanford:
    def __init__(self, to: list, start: int, goal: int):
        self.N = len(to)
        self.to = [s[:] for s in to]
        self.start = start
        self.goal = goal
        self.dist = [inf] * self.N
        self.dist[start] = 0
        self.exists_negative_cycle = False
        self.exists_negative_cycle_stog = False
        self.is_updated = [False] * self.N

    # self.distを更新
    def update(self) -> None:
        for _ in range(self.N - 1):
            for v, s in enumerate(self.to):
                if not s:
                    continue
                for nv, w in s:
                    if self.dist[nv] > self.dist[v] + w:
                        self.dist[nv] = self.dist[v] + w

    # グラフの負閉路検出
    def detection(self) -> bool:
        for v, s in enumerate(self.to):
            if not s:
                continue
            for nv, w in s:
                if self.dist[nv] > self.dist[v] + w:
                    self.dist[nv] = self.dist[v] + w
                    self.exists_negative_cycle = True
        return self.exists_negative_cycle

    # スタートからゴールまでのパスの負閉路検出
    def detection_stog(self) -> bool:
        for _ in range(self.N):
            for v, s in enumerate(self.to):
                if not s:
                    continue
                for nv, w in s:
                    if self.dist[nv] > self.dist[v] + w:
                        self.dist[nv] = self.dist[v] + w
                        self.is_updated[nv] = True
                    if self.is_updated[v] is True:
                        self.is_updated[nv] = True
        self.exists_negative_cycle_stog = self.is_updated[self.goal]
        return self.exists_negative_cycle_stog


N, M = list(map(int, input().split()))
to = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    to[a].append((b, -c))
BF = Bellmanford(to, 0, N - 1)
BF.update()
if BF.detection_stog():
    ans = "inf"
else:
    ans = -BF.dist[N - 1]
print(ans)

-# ベルマンフォード法 -# 計算量O(VE) V:頂点数, E:辺の数 -# [引数]   n:頂点数, edges:辺集合, start:始点, end:終点 -# [返り値] dist:startからの最短距離, exists_negative_cycle: 負閉路が存在するかどうか -def bellmanford(n: int, edges: list, start: int, goal: int) -> (list, bool): -    dist = [inf] * n -    dist[start] = 0 -    exist_negative_cycle = True -    # 負閉路を含まないとき、頂点数nなら更新は高々n-1回で済む -    for _ in range(N - 1): -        for v, nv, w in edges: -            if dist[nv] > dist[v] + w: -                dist[nv] = dist[v] + w -    # (1)グラフに負閉路が含まれるときの検出 -    # N回目で更新があったとき、グラフは負閉路を含む -    # for v, nv, w in edges: -    #     if dist[nv] > dist[v] + w: -    #         is_cycle = False -    # (2)startとendのパスに負閉路が含まれるときの検出 -    is_updated = [False] * n -    for _ in range(N): -        for v, nv, w in edges: -            if dist[nv] > dist[v] + w: -                dist[nv] = dist[v] + w -                is_updated[nv] = True -            if is_updated[v] is True: -                is_updated[nv] = True -    exist_negative_cycle = is_updated[goal] -    return dist, exist_negative_cycle +# ベルマンフォード法 計算量(VE) +# [引数]: 隣接リスト, 始点, 終点 +class Bellmanford: +    def __init__(self, to: list, start: int, goal: int): +        self.N = len(to) +        self.to = [s[:] for s in to] +        self.start = start +        self.goal = goal +        self.dist = [inf] * self.N +        self.dist[start] = 0 +        self.exists_negative_cycle = False +        self.exists_negative_cycle_stog = False +        self.is_updated = [False] * self.N + +    # self.distを更新 +    def update(self) -> None: +        for _ in range(self.N - 1): +            for v, s in enumerate(self.to): +                if not s: +                    continue +                for nv, w in s: +                    if self.dist[nv] > self.dist[v] + w: +                        self.dist[nv] = self.dist[v] + w + +    # グラフの負閉路検出 +    def detection(self) -> bool: +        for v, s in enumerate(self.to): +            if not s: +                continue +            for nv, w in s: +                if self.dist[nv] > self.dist[v] + w: +                    self.dist[nv] = self.dist[v] + w +                    self.exists_negative_cycle = True +        return self.exists_negative_cycle + +    # スタートからゴールまでのパスの負閉路検出 +    def detection_stog(self) -> bool: +        for _ in range(self.N): +            for v, s in enumerate(self.to): +                if not s: +                    continue +                for nv, w in s: +                    if self.dist[nv] > self.dist[v] + w: +                        self.dist[nv] = self.dist[v] + w +                        self.is_updated[nv] = True +                    if self.is_updated[v] is True: +                        self.is_updated[nv] = True +        self.exists_negative_cycle_stog = self.is_updated[self.goal] +        return self.exists_negative_cycle_stog -edges = [] +to = [[] for _ in range(N)] -    edges.append((a, b, -c)) -dist, exist_negative_cycle = bellmanford(N, edges, 0, N - 1) -if exist_negative_cycle is True: +    to[a].append((b, -c)) +BF = Bellmanford(to, 0, N - 1) +BF.update() +if BF.detection_stog(): -    ans = -dist[N - 1] +    ans = -BF.dist[N - 1]