#![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 = g.bellman_ford(0);

    match &res[n-1] {
        &None => (),
        &Some(ref x) => {
            match x {
                &BellmanFordResult::NegInf => println!("-1"),
                &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),
    NegInf,
}

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

        for i in 0..n {
            for s in 0..n {
                for &Edge::<T>{from: _, to: t, cost: ref c} in &self.nodes[s] {
                    match ret[s].clone() {
                        None => (),
                        Some(BellmanFordResult::NegInf) => {
                            ret[t] = Some(BellmanFordResult::NegInf);
                        },
                        Some(BellmanFordResult::Dist(ds)) => {
                            match ret[t].clone() {
                                None => {
                                    ret[t] = Some(BellmanFordResult::Dist(ds + c.clone()));
                                },
                                Some(BellmanFordResult::NegInf) => (),
                                Some(BellmanFordResult::Dist(dt)) => {
                                    if dt > ds.clone() + c.clone() && i == n-1 {
                                        ret[t] = Some(BellmanFordResult::NegInf);
                                    }else{
                                        ret[t] = Some(BellmanFordResult::Dist(cmp::min(dt, ds + c.clone())));
                                    }
                                }
                            }
                        },
                    }
                }
            }
        }

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


Measured memory_bytes: 4476