let () = Scanf.scanf "%d %d %d\n" @@ fun n m p ->
  let abc = Array.init m @@ fun _ ->
    Scanf.scanf "%d %d %d\n" @@ fun a b c -> a - 1, b - 1, c - p in
  let d = Array.make n (-1145141919) in
  let ng = Array.make n false in
  d.(0) <- 0;
  for i = 0 to 2 * n - 1 do
    Array.iter (fun (a, b, c) ->
      if d.(b) < d.(a) + c then begin
        d.(b) <- d.(a) + c;
          if n - 1 <= i then
            ng.(b) <- true
      end) abc
  done;
  if ng.(n - 1)
  then print_endline "-1"
  else Printf.printf "%d\n" @@ max 0 d.(n - 1)