#![allow(unused_imports, unused_macros)]

macro_rules! get{
    ($t:ty) => {
        {
            let cin = stdin();
            let mut cin = cin.lock();
            
            let token =
                cin.by_ref().bytes().map(|c| c.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect::<String>();

            try!(token.parse::<$t>())
        }
    }
}

macro_rules! input{
    ($($id:ident: $t:ty),*) => {
        $(
            let $id = get!($t);
        )*;
    }
}

macro_rules! input_vec{
    ($id:ident: Vec<$t:ty>, $n:expr) => {
        let $id = (0..$n).map(|_| get!($t).unwrap()).collect::<Vec<$t>>();
    }
}

use std::io::{Read,stdin};
use std::str::*;
use std::error::Error;
use std::cmp;


fn main(){
    while let Ok(_) = solve() {}
}

fn solve() -> Result<(),Box<std::error::Error>>{
    input!(n: usize, m: usize, p: i32);
    
    let mut g = Graph::<i32>::new(n);

    for _ in 0..m {
        input!(a: usize, b: usize, c: i32);
        g.add_edge(a-1, b-1, p-c);
    }

    let res = bellman_ford(&g,0);

    //    println!("{:?}", res);

    match res[n-1] {
        BellmanFordResult::NegInf => println!("-1"),
        BellmanFordResult::Inf => (),
        BellmanFordResult::Dist(d) => println!("{}", cmp::max(0, -d)),
    }
    
    Ok(())
}



#[derive(Debug, Clone)]
struct Edge<T>{
    from: usize,
    to: usize,
    cost: T
}

#[derive(Debug)]
struct Graph<T>{
    nodes: Vec<Vec<Edge<T>>>
}


#[allow(dead_code)]
impl<T> Graph<T>
    where T: Clone
{
    fn new(n: usize) -> Graph<T>{
        let nodes: Vec<Vec<Edge<T>>> = vec![vec![]; n];

        Graph{
            nodes: nodes
        }
    }

    fn add_edge(&mut self, s: usize, t: usize, cost: T){
        self.nodes[s].push(
            Edge{
                from: s,
                to: t,
                cost: cost
            }
        );
    }

    fn size(&self) -> usize{
        self.nodes.len()
    }
}

use std::ops::Add;
use std::fmt::Debug;

#[derive(Debug,Clone, PartialEq, Eq)]
enum BellmanFordResult<T>{
    Dist(T),
    Inf,
    NegInf,
}

fn bellman_ford<T>(g: &Graph<T>, src: usize) -> Vec<BellmanFordResult<T>>
where
    T: Clone + Default + Add<Output=T> + Debug + Ord
{
    let mut ret = vec![BellmanFordResult::Inf; g.size()];
    ret[src] = BellmanFordResult::Dist(T::default());

    let n = g.size();

    for i in 0..n {
        for s in 0..n {
            for &Edge::<T>{from: _, to: t, cost: ref c} in &g.nodes[s] {

                match ret[s].clone() {
                    BellmanFordResult::Inf => (),
                    BellmanFordResult::NegInf => {
                        ret[t] = BellmanFordResult::NegInf;
                    },
                    BellmanFordResult::Dist(ds) => {
                        match ret[t].clone() {
                            BellmanFordResult::Inf => {
                                ret[t] = BellmanFordResult::Dist(ds + c.clone());
                            },
                            BellmanFordResult::NegInf => (),
                            BellmanFordResult::Dist(dt) => {
                                if dt > ds.clone() + c.clone() && i == n-1 {
                                    ret[t] = BellmanFordResult::NegInf;
                                }else{
                                    ret[t] = BellmanFordResult::Dist(cmp::min(dt, ds + c.clone()));
                                }
                            }
                        }
                    },
                }
            }
        }
    }

    for _ in 0..n {
        for nodes in &g.nodes{
            for &Edge{from: s, to: t, cost: _} in nodes {
                if ret[s] == BellmanFordResult::NegInf {
                    ret[t] = BellmanFordResult::NegInf;
                }
            }
        }
    }
        
    ret
}


Measured memory_bytes: 4476