program main
  implicit none
  integer(8) :: n, m, i
  integer(8), allocatable :: edges(:, :)
  read *, n, m
  allocate (edges(3, m))
  do i = 1, m
    read *, edges(:, i)
  end do
  edges(3, :) = -1 * edges(3, :)
  call bellman_ford(n, m, edges)
  contains
  subroutine bellman_ford(n, m, edges)
    ! ベルマンフォードの変形
    ! https://ja.wikipedia.org/wiki/ベルマン–フォード法#アルゴリズム
    integer(8), intent(in) :: n, m, edges(3, m)
    integer(8) :: dist(n), predecessor(n), i, j, u, v, w, ptr
    logical :: used(n)

    ! Step1 グラフの初期化
    dist = 2 * 10_8 ** 18
    dist(1) = 0
    predecessor = -1

    ! Step2 辺の緩和を反復
    do i = 1, n - 1
      do j = 1, m
        u = edges(1, j)
        v = edges(2, j)
        w = edges(3, j)
        if (dist(v) > dist(u) + w) then
          dist(v) = dist(u) + w
          predecessor(v) = u
        end if
      end do
    end do

    used = .false.
    ptr = n
    do while (1 <= ptr)
      if (used(ptr)) exit
      used(ptr) = .true.
      ptr = predecessor(ptr)
    end do

    ! Step3 負の重みの閉路がないかチェック
    do j = 1, m
      u = edges(1, j)
      v = edges(2, j)
      w = edges(3, j)
      if (dist(u) + w < dist(v)) then
        if (used(u) .or. used(v)) then
          print "(a)", "inf"
          return
        end if
      end if
    end do
    print "(i0)", -1 * dist(n)
  end subroutine bellman_ford
end program main
