#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>

#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <random>
#include <complex>
#include <utility>
#include <tuple>
#include <memory>

#include <array>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <csignal>
#include <cstdint>
#include <cstddef>

#ifdef ONLINE_JUDGE
#define NDEBUG
#endif
#include <cassert>
#include <stdexcept>
#include <exception>

/*
// << pair
template <typename T1, typename T2>std::ostream&operator<<(std::ostream&os,const std::pair<T1,T2>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
// << container
template<typename,template<typename...> class...>struct is_instantiation_of:public std::false_type{};
template<template<typename...>class U,template<typename...>class...Us,typename...T>struct is_instantiation_of<U<T...>,U,Us...>:public std::true_type{};
template<typename S,template<typename...>class U,template<typename...>class...Us>struct is_instantiation_of<S,U,Us...>:std::bool_constant<is_instantiation_of<S,Us...>::value>{};
template<typename C,typename=std::enable_if_t<is_instantiation_of<C,std::vector,std::set,std::map,std::unordered_set,std::unordered_map,std::multiset,std::multimap,std::unordered_multiset,std::unordered_multimap>::value>>std::ostream&operator<<(std::ostream&os,const C&v){bool first=true;os<<"[";for(auto i:v){if(!first)os<<", ";else first=false;os<<i;}return os<<"]";}
*/

struct Debugger{template<typename T>Debugger&operator,(const T&v){std::cerr<<v<<" "; return *this;}} dbg;
#ifndef NDEBUG
#define debug(args...) do {dbg,args; cerr << "\n";} while(0)
#else
#define debug(args...)
#endif

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ITER(i, s, e) for (auto i((s)); i != (e); ++i)
#define IT(i, c) ITER(i, (c).begin(), (c).end())

using namespace std;

using ui = uint32_t;
using ll = int64_t;
using ull = uint64_t;
template <typename T = int> using Pt = complex<T>;

template <typename T>
T cross(const Pt<T>& a, const Pt<T>& b) { return a.real() * b.imag() - a.imag() * b.real(); }

template <typename T>
bool cmpPt(const Pt<T>& a, const Pt<T>& b) {
    return a.real() < b.real() || (a.real() == b.real() && a.imag() < b.imag());
}
// END TEMPLATE

constexpr int MAX_N = 2500 + 10;
constexpr ll INF = 1e18;

pair<ll, bool> SPFA(int N, int M, const vector<vector<pair<int, ll>>>& E) {
    //debug(E);
    vector<ll> d(N, INF);
    vector<int> inq(N), plen(N, -1);
    d[0] = 0;
    plen[0] = 0;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int u = q.front(); q.pop(); inq[u] = 0;
        for (auto e : E[u]) {
            int v = e.first;
            ll w = e.second;
            if (d[u] + w < d[v]) {
                d[v] = d[u] + w;
                plen[v] = plen[u] + 1;
                if (!inq[v] && plen[v] <= N) {
                    q.push(v); inq[v] = 1;
                }
            }
        }
    }
    function<void(int)> dfs;
    dfs = [&d, &E, &dfs] (int u) {
        if (d[u] == -INF) return;
        d[u] = -INF;
        for (auto e : E[u]) {
            dfs(e.first);
        }
    };
    REP(u, N) if (plen[u] >= N) dfs(u);
    return {d[N-1], d[N-1] != -INF};
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M; ll P; cin >> N >> M >> P;
    vector<vector<pair<int, ll>>> E(N);
    REP(i, M) {
        int u, v; ll C; cin >> u >> v >> C; --u, --v;
        E[u].push_back({v, -C + P});
    }

    pair<ll, int> ans = SPFA(N, M, E);
    cout << (ans.second ? max(-ans.first, ll(0)) : -1) << '\n';

    return 0;
}


Measured memory_bytes: 512