let rec fold_n n f v = if n <= 0 then v else fold_n (n-1) f (f v)
let inf = 10101010101010

let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let a = Array.init m (fun _ -> Scanf.scanf " %d %d %d" (fun a b c -> a-1,b-1,c)) in

  let reach = begin
    let g = Array.init n (fun _ -> []) in
    a |> Array.iter (fun (u,v,_) -> g.(v) <- u :: g.(v));
    let vis = Array.make n false in
    let rec f u =
      vis.(u) <- true;
      List.iter (fun v -> if not vis.(v) then f v) g.(u)
    in f (n-1);
    vis
  end in

  let sc = Array.make n (-inf) in sc.(0) <- 0;
  let mem = Array.make n false in
  let has_loop = true |> fold_n n (fun upd ->
    if not upd then false else begin
      Array.fill mem 0 n false;
      Array.fold_left (fun b (u,v,c) ->
        let b' = sc.(u) + c > sc.(v) in
        if b' then (mem.(v) <- true; sc.(v) <- sc.(u) + c);
        b || b'
        ) false a
    end)
  in
  let inf_loop = has_loop && begin
    Array.init n (fun i -> reach.(i) && mem.(i)) |> Array.fold_left (||) false
  end in

  if inf_loop then
    print_endline "inf"
  else
    Printf.printf "%d\n" sc.(n-1)
