open Scanf
open Printf

let iota n : int list =
  let rec f n ans = if n = 0 then ans else f (n - 1) ((n - 1) :: ans) in
  f n []

let () =
  let n, m, p = scanf " %d %d %d" (fun a b c -> a, b, c) in
  let es = Array.init m @@ fun _ -> scanf " %d %d %d" @@ fun a b c -> (a - 1), (b - 1), c - p in
  let inf = max_int / 4 in
  let dist = Array.make n (-inf) in
  let from_s = Array.make n false in
  let from_t = Array.make n false in
  dist.(0) <- 0;
  from_s.(0) <- true;
  from_t.(n - 1) <- true;
  for _ = 0 to n do
    es |> Array.iter @@ fun (a, b, c) ->
      dist.(b) <- max dist.(b) (dist.(a) + c);
      from_s.(b) <- from_s.(b) || from_s.(a);
      from_t.(a) <- from_t.(a) || from_t.(b)
  done;
  let tmp = Array.copy dist in
  for _ = 0 to n do
    es |> Array.iter @@ fun (a, b, c) ->
      dist.(b) <- max dist.(b) (dist.(a) + c);
  done;
  if (iota n |> List.exists (fun i -> from_s.(i) && from_t.(i) && dist.(i) <> tmp.(i))) then
    printf "-1\n"
  else
    printf "%d\n" @@ max 0 dist.(n - 1);