//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::i64::MAX;
use std::io::Read;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        m: usize,
        p: i64,
        edges: [(usize1,usize1,i64);m]
    }

    let mut adj_list = vec![vec![]; n];
    let mut rev_adj_list = vec![vec![]; n];

    // 隣接リストを作る
    for &(from, to, coin) in &edges {
        adj_list[from].push(to);
        rev_adj_list[to].push(from);
    }

    // まず、Nに到達できない頂点と、1から到達できない頂点を消す

    let mut que = BinaryHeap::new();
    // (n - dist,node) n-distにするのは最大のものを取り出す＝頂点1から近いものを取り出すとしてBFSにするため
    let mut toN_from1 = vec![false; n];

    // from1の検証
    que.push((n, 0));
    let mut visited_from_head = vec![false; n];
    while !que.is_empty() {
        let (dist, node) = que.pop().unwrap();

        for &i in &adj_list[node] {
            if !visited_from_head[i] {
                visited_from_head[i] = true;
                que.push((dist - 1, i));
            }
        }
    }

    que.clear();

    // toNの検証
    que.push((n, n - 1));
    let mut visited_from_tail = vec![false; n];
    while !que.is_empty() {
        let (dist, node) = que.pop().unwrap();

        for &i in &rev_adj_list[node] {
            if !visited_from_tail[i] {
                visited_from_tail[i] = true;
                que.push((dist - 1, i));
            }
        }
    }

    for i in 0..n {
        if visited_from_head[i] && visited_from_tail[i] {
            toN_from1[i] = true;
        }

        if i == 0 || i == n - 1 {
            toN_from1[i] = true;
        }
    }

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

    let mut effective_edges = vec![];
    for &e in &edges {
        if toN_from1[e.1] {
            effective_edges.push(e);
        }
    }

    let mut bellman_dist = vec![MAX; n];
    bellman_dist[0] = 0;
    // ベルマンフォード1週目
    for i in 0..2 * n {
        for &(from, to, coin) in &effective_edges {
            let dist = -(coin - p);
            if bellman_dist[from] != MAX {
                bellman_dist[to] = cmp::min(bellman_dist[from] + dist, bellman_dist[to]);
            }
        }
    }
    let mut effective_dist_sum_n = 0;
    for i in 0..n {
        if bellman_dist[i] != MAX {
            effective_dist_sum_n += bellman_dist[i];
        }
    }

    // ベルマンフォードあと1回
    for &(from, to, coin) in &effective_edges {
        let dist = -(coin - p);
        if bellman_dist[from] != MAX {
            bellman_dist[to] = cmp::min(bellman_dist[from] + dist, bellman_dist[to]);
        }
    }
    let mut effective_dist_sum_np1 = 0;
    for i in 0..n {
        if bellman_dist[i] != MAX {
            effective_dist_sum_np1 += bellman_dist[i];
        }
    }

    //println!("{} {}", effective_dist_sum_n, effective_dist_sum_np1);
    if effective_dist_sum_n != effective_dist_sum_np1 {
        println!("{}", -1);
    } else {
        if bellman_dist[n - 1] < 0 {
            println!("{}", -bellman_dist[n - 1]);
        } else {
            println!("{}", 0);
        }
    }
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2804