#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| min!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| max!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

struct BellmanFord;

#[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Copy)]
enum Cost {
    MinusInfinity,
    Value(i64),
    Infinity,
}

use std::ops::Add;
impl Add for Cost {
    type Output = Cost;
    fn add(self, other: Cost) -> Cost {
        use Cost::{MinusInfinity, Value, Infinity};
        match (self, other) {
            (Infinity, _) => Infinity,
            (_, Infinity) => Infinity,
            (Value(x), Value(y)) => Value(x + y),
            _ => MinusInfinity
        }
    }
}

#[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Copy)]
struct CostedEdge(usize, usize, Cost);

impl BellmanFord {
    fn yen(edges: &Vec<CostedEdge>) -> Vec<CostedEdge> {
        let mut edges_f = vec![];
        let mut edges_b = vec![];
        for &CostedEdge(i, j, c) in edges.iter() {
            if i <= j {
                edges_f.push(CostedEdge(i, j, c));
            } else {
                edges_b.push(CostedEdge(i, j, c));
            }
        }
        edges_f.sort();
        edges_b.sort();
        edges_b.reverse();
        edges_f.iter().chain(edges_b.iter()).map(|&p| p).collect()
    }
    fn shortest(n: usize, edges: &Vec<CostedEdge>, s: usize, t: usize) -> Cost {
        let mut dist = vec![Cost::Infinity; n];
        dist[s] = Cost::Value(0);
        for _ in 1..n {
            for &CostedEdge(i, j, c) in edges.iter() {
                if dist[j] > dist[i] + c {
                    dist[j] = dist[i] + c;
                }
            }
        }
        trace!(&dist);
        for &CostedEdge(i, j, c) in edges.iter() {
            if dist[i] + c < dist[j] {
                dist[i] = Cost::MinusInfinity
                // return Cost::MinusInfinity
            }
        }
        for _ in 1..n {
            for &CostedEdge(i, j, c) in edges.iter() {
                if dist[j] > dist[i] + c {
                    dist[j] = dist[i] + c;
                }
            }
        }
        trace!(&dist);
        dist[t]
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let m: usize = sc.cin();
    let p: i64 = sc.cin();
    let mut edges = vec![];
    let mut self_edges = vec![];
    for _ in 0..m {
        let u: usize = sc.cin();
        let v: usize = sc.cin();
        let c: i64 = sc.cin();
        if u == v && c > p {
            self_edges.push(CostedEdge(u - 1, u - 1, Cost::Value(p - c)));
        } else if u != v {
            edges.push(CostedEdge(u - 1, v - 1, Cost::Value(p - c)));
        }
    }
    let edges = BellmanFord::yen(&edges);

    // reachability
    {
        let mut neigh = vec![vec![]; n];
        let mut neigh_rev = vec![vec![]; n];
        for &CostedEdge(i, j, _) in edges.iter() {
            neigh[i].push(j);
            neigh_rev[j].push(i);
        }

        let mut reach_from_s = vec![false; n];
        let mut reach_to_t = vec![false; n];

        let mut stack = vec![0];
        while let Some(u) = stack.pop() {
            if reach_from_s[u] { continue }
            reach_from_s[u] = true;
            for &v in neigh[u].iter() {
                stack.push(v);
            }
        }

        let mut stack = vec![n-1];
        while let Some(u) = stack.pop() {
            if reach_to_t[u] { continue }
            reach_to_t[u] = true;
            for &v in neigh_rev[u].iter() {
                stack.push(v);
            }
        }

        for &CostedEdge(i, _, _) in self_edges.iter() {
            if reach_from_s[i] && reach_to_t[i] {
                put!(-1);
                return;
            }
        }

    }

    let result = BellmanFord::shortest(n, &edges, 0, n - 1);
    match result {
        Cost::Value(x) => {
            put!(max!(0, -x));
        }
        _ => {
            put!(-1);
        }
    }

}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4476