output_description: Print the maximum possible score at the end of the game, if it is finite. If
  it is possible to increase the score indefinitely, print `inf`.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M  
      a_1 b_1 c_1  
      a_2 b_2 c_2
      :  
      a_M b_M c_M
attempt: # -*- coding: utf-8 -*-
  import sys
  import math
  import os
  import itertools
  import string
  import heapq
  import _collections
  from collections import Counter
  from collections import defaultdict
  from functools import lru_cache
  import bisect
  
  
  class Scanner:
      @staticmethod
      def int():
          return int(sys.stdin.readline().rstrip())
  
      @staticmethod
      def string():
          return sys.stdin.readline().rstrip()
  
      @staticmethod
      def map_int():
          return [int(x) for x in Scanner.string().split()]
  
      @staticmethod
      def string_list(n):
          return [input() for i in range(n)]
  
      @staticmethod
      def int_list_list(n):
          return [Scanner.map_int() for i in range(n)]
  
      @staticmethod
      def int_cols_list(n):
          return [int(input()) for i in range(n)]
  
  
  class Math:
      @staticmethod
      def gcd(a, b):
          if b == 0:
              return a
          return Math.gcd(b, a % b)
  
      @staticmethod
      def lcm(a, b):
          return (a * b) // Math.gcd(a, b)
  
      @staticmethod
      def roundUp(a, b):
          return -(-a // b)
  
      @staticmethod
      def toUpperMultiple(a, x):
          return Math.roundUp(a, x) * x
  
      @staticmethod
      def toLowerMultiple(a, x):
          return (a // x) * x
  
      @staticmethod
      def nearPow2(n):
          if n <= 0:
              return 0
          if n & (n - 1) == 0:
              return n
          ret = 1
          while n > 0:
              ret <<= 1
              n >>= 1
          return ret
  
      @staticmethod
      def sign(n):
          if n == 0:
              return 0
          if n < 0:
              return -1
          return 1
  
      @staticmethod
      def isPrime(n):
          if n < 2:
              return False
          if n == 2:
              return True
          if n % 2 == 0:
              return False
          d = int(n**0.5) + 1
          for i in range(3, d + 1, 2):
              if n % i == 0:
                  return False
          return True
  
  
  MOD = int(1e09) + 7
  INF = int(1e15)
  
  
  def main():
      # sys.stdin = open("sample.txt")
      N, M = Scanner.map_int()
  
      class Edge:
          def __init__(self, a, b, c):
              self.from_ = a
              self.to_ = b
              self.cost_ = c
  
      edges = [Edge] * M
      for i in range(M):
          a, b, c = Scanner.map_int()
          a -= 1
          b -= 1
          c = -c
          edges[i] = Edge(a, b, c)
      dist = [INF] * N
      dist[0] = 0
      for loop in range(N - 1):
          for i in range(M):
              e = edges[i]
              if dist[e.from_] == INF:
                  continue
              if dist[e.to_] > dist[e.from_] + e.cost_:
                  dist[e.to_] = dist[e.from_] + e.cost_
      ans = dist[N - 1]
      negatives = [False] * N
      for loop in range(N):
          for i in range(M):
              e = edges[i]
              if dist[e.from_] == INF:
                  continue
              if dist[e.to_] > dist[e.from_] + e.cost_:
                  dist[e.to_] = dist[e.from_] + e.cost_
                  negatives[e.to_] = True
              if negatives[e.from_]:
                  negatives[e.to_] = True
      if negatives[N - 1]:
          print("inf")
      else:
          print(-ans)
  
  
  if __name__ == "__main__":
      main()
  
problem_description: Statement
  
  There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M)
  points from vertex a_i to vertex b_i, and has a weight c_i. We will play the
  following single-player game using this graph and a piece.
  
  Initially, the piece is placed at vertex 1, and the score of the player is set
  to 0. The player can move the piece as follows:
  
    * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i.
  
  The player can end the game only when the piece is placed at vertex N. The
  given graph guarantees that it is possible to traverse from vertex 1 to vertex
  N.
  
  When the player acts optimally to maximize the score at the end of the game,
  what will the score be? If it is possible to increase the score indefinitely,
  print `inf`.
samples: [{"input": "3 3\n    1 2 4\n    2 3 3\n    1 3 5", "output": "7\n    \n\nThere are two ways to move the piece to vertex N=3:\n\n  * vertex 1 \u2192 vertex 2 \u2192 vertex 3 : score 4+3=7\n  * vertex 1 \u2192 vertex 3 : score 5\n\nThus, the maximum possible score at the end of the game is 7.\n\n* * *"}, {"input": "2 2\n    1 2 1\n    2 1 1", "output": "inf\n    \n\nIt is possible to increase the score indefinitely by alternating between\nvertex 1 and 2.\n\n* * *"}, {"input": "6 5\n    1 2 -1000000000\n    2 3 -1000000000\n    3 4 -1000000000\n    4 5 -1000000000\n    5 6 -1000000000", "output": "-5000000000"}]