(* 辺は (from,to,cost) の組 *)
open Scanf
open Printf

type edge = int * int * int;;
let (n,m,p) = sscanf (read_line ()) "%d %d %f" (fun a b c -> (a,b,c));;
let rec input = function
  | 0 -> []
  | t -> (sscanf (read_line ()) "%d %d %f" (fun a b c-> (a-1,b-1, -.(c -. p)))) :: input(t-1);;

let dist = Array.make n infinity;;
dist.(0) <- 0.0;;
let edges = input m;;
let loop_flag = ref false;;
let n_count_value = ref 0.0;;

let _ = 
for i = 0 to 2 * n do
    if i = n - 1 then n_count_value := dist.(n-1) else ();
    List.iter (fun x -> 
      let (f,t,c) = x in
      if (dist.(t) > dist.(f) +. c) then
        let _ = dist.(t) <-  dist.(f) +. c in
        if (i = n-1) && ((t == n-1) || (f == n-1)) then 
          (*(printf "Loop found ! edge = f:%d t:%d") f t *)
          loop_flag := true
        else ()
      else ()
    ) edges
done;;

let _ = 
if dist.(n-1) = infinity || int_of_float !n_count_value != int_of_float dist.(n-1) then
  printf "%d\n" (-1)
else
  printf "%d\n" (max 0 (int_of_float (-.dist.(n-1))));;
