use std::borrow::BorrowMut;
use std::cmp::max;
use std::fs::File;
use std::io::{stdout, BufWriter, Read, Write};
use std::thread;

fn main() {
    thread::Builder::new()
        .stack_size(32 * 1024 * 1024) // 32MB
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

/// ローカル環境なら _in.txt から入力を受ける
fn read_input() -> String {
    let stdin = std::io::stdin();
    let mut s = String::new();
    match option_env!("LOCAL") {
        Some(_) => File::open("src/_in.txt")
            .expect("File not found")
            .read_to_string(&mut s)
            .unwrap(),
        None => stdin.lock().read_to_string(&mut s).unwrap(),
    };
    s
}

fn bellman_ford(graph: &Vec<Vec<(usize, i64)>>, from_v: usize, to_v: usize) -> Option<i64> {
    /// graph 上で from_v から到達できるかどうかのベクタ
    fn reachable(graph: &Vec<Vec<(usize, i64)>>, from_v: usize) -> Vec<bool> {
        let mut ret: Vec<bool> = vec![false; graph.len()];
        ret[from_v] = true;

        // dfs
        let mut stack: Vec<usize> = vec![];
        stack.push(from_v);
        while let Some(v) = stack.pop() {
            for &(u, _) in &graph[v] {
                if !ret[u] {
                    ret[u] = true;
                    stack.push(u);
                }
            }
        }
        ret
    }

    // from_v から到達でき、かつ to_v へ到達できる頂点のみ考える
    // これら以外には負閉路があっても関係ない
    let mut vertices: Vec<usize> = vec![];
    let mut rev: Vec<Vec<(usize, i64)>> = vec![vec![]; graph.len()];
    for (v, edges) in graph.iter().enumerate() {
        for &(u, d) in edges {
            rev[u].push((v, d));
        }
    }
    let r1 = reachable(&graph, from_v);
    let r2 = reachable(&rev, to_v);
    for v in 0..graph.len() {
        if r1[v] && r2[v] {
            vertices.push(v);
        }
    }

    // bellman ford
    let inf = i64::pow(10, 18);
    let mut dist = vec![inf; graph.len()];
    dist[from_v] = 0;
    let mut updated = true;
    for _ in 0..graph.len() {
        updated = false;
        for v in &vertices {
            for &(u, d) in &graph[*v] {
                if dist[*v] + d < dist[u] {
                    dist[u] = dist[*v] + d;
                    updated = true;
                }
            }
        }
        if !updated {
            break;
        }
    }

    if !updated && dist[to_v] < inf {
        Some(dist[to_v])
    } else {
        None
    }
}

fn run() {
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    let input = read_input();
    let mut input = input.split_whitespace();

    let in_n: i64 = input.next().unwrap().parse().unwrap();
    let in_m: i64 = input.next().unwrap().parse().unwrap();
    let in_p: i64 = input.next().unwrap().parse().unwrap();
    let abc: Vec<(i64, i64, i64)> = (0..in_m)
        .map(|_| {
            let r: Vec<i64> = input
                .borrow_mut()
                .take(3 as usize)
                .map(|s| s.parse().unwrap())
                .collect();
            (r[0], r[1], r[2])
        })
        .collect();

    let mut graph: Vec<Vec<(usize, i64)>> = vec![vec![]; in_n as usize];
    for (a, b, c) in abc {
        graph[a as usize - 1].push((b as usize - 1, in_p - c));
    }

    if let Some(dist) = bellman_ford(&graph, 0, in_n as usize - 1) {
        writeln!(out, "{}", max(-dist, 0)).ok();
    } else {
        writeln!(out, "{}", -1).ok();
    }
}


Measured memory_bytes: 8572