let bellman_ford d es =
  for i = 1 to Array.length d - 1 do
    List.iter (fun (a, b, c) ->
      d.(b) <- min d.(b) (d.(a) + c)) es
  done

let () =
  let n, m = Scanf.scanf "%d %d\n" (fun n m -> n, m) in
  let abcs = Array.to_list @@ Array.init m (fun _ -> Scanf.scanf "%d %d %d\n" (fun a b c -> a - 1, b - 1, -c)) in
  let d = Array.make n 1000000000000 in
  d.(0) <- 0;
  bellman_ford d abcs;
  if List.exists (fun (a, b, c) -> d.(a) + c < d.(b)) abcs then print_endline "inf"
  else Printf.printf "%d\n" (-d.(n - 1))
