let bellman_ford d es =
  Array.iter (fun _ ->
    List.iter (fun (a, b, c) ->
      d.(b) <- min d.(b) (d.(a) +. c)) es) d;
  List.iter (fun (a, b, c) ->
    if d.(a) +. c < d.(b) then d.(b) <- neg_infinity)

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, -. float_of_int c)) in
  let d = Array.make n infinity in
  d.(0) <- 0.;
  bellman_ford d abcs;
  if d.(n - 1) = neg_infinity then print_endline "inf"
  else Printf.printf "%d\n" (- int_of_float d.(n - 1))
