local n, m = io.read("*n", "*n")
local edge = {}
for i = 1, n do edge[i] = {} end
for i = 1, m do
  local a, b, c = io.read("*n", "*n", "*n")
  edge[a][b] = c
end

local taskstate = {}
for i = 1, n do taskstate[i] = false end
local tasks = {}
local tasknum = 0
local done = 0
local tasklim = n + 1
local updatecount = 0
local len = {}
for i = 1, n do len[i] = -1000000000000 end
len[1] = 0
local function addtask(idx)
  if(not taskstate[idx]) then
    taskstate[idx] = true
    tasknum = tasknum + 1
    local taskidx = tasknum % tasklim
    if taskidx == 0 then taskidx = tasklim end
    tasks[taskidx] = idx
    if idx == n then
      updatecount = updatecount + 1
      if n + 2 < updatecount then
        return false
      end
    end
  end
  return true
end
addtask(1)

local ret = true
while(done < tasknum) do
  done = done + 1
  local taskidx = done % tasklim
  if(taskidx == 0) then taskidx = tasklim end
  local src = tasks[taskidx]
  taskstate[src] = false

  for dst, cost in pairs(edge[src]) do
    if len[dst] < len[src] + cost then
      len[dst] = len[src] + cost
      ret = addtask(dst) and ret
    end
  end
  if not ret then break end
  if 5000000 < done then break end
end
if ret then
  print(len[n])
else
  print("inf")
end
