#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール
struct edge {
    ll from, to, cost;
};

// 処理内容
int main() {
    
    ll n, m, p; cin >> n >> m >> p;
    vector<edge> e(m);
    vector<vector<pair<ll, ll>>> g(n), h(n);
    REP(i, m) {
        ll a, b, c; cin >> a >> b >> c;
        a--; b--; // 0-indexed
        c -= p;
        e[i] = {a, b, c};
        g[a].emplace_back(b, c);
        h[b].emplace_back(a, c);
    }

    // Jokyo
    vector<bool> vstg(n, false), vsth(n, false), vst(n, false);
    {
        deque<ll> q = {0};
        vstg[0] = true;
        while (q.size()) {
            ll u = q.front(); q.pop_front();
            for (pair<ll, ll> vc : g[u]) {
                if (!vstg[vc.first]) {
                    vstg[vc.first] = true;
                    q.push_back(vc.first);
                }
            }
        }
    }
    {
        deque<ll> q = {n-1};
        vsth[n-1] = true;
        while (q.size()) {
            ll u = q.front(); q.pop_front();
            for (pair<ll, ll> vc : h[u]) {
                if (!vsth[vc.first]) {
                    vsth[vc.first] = true;
                    q.push_back(vc.first);
                }
            }
        }
    }
    REP(i, n) {
        vst[i] = vstg[i] && vsth[i];
    }
    DSRNG(i, m-1, 0) {
        if (!vst[e[i].from] || !vst[e[i].to]) {
            e.erase(e.begin() + i);
        }
    }
    m = e.size();

    // Does it have a halo?: Bellman-Ford; O(NM)
    vector<ll> dbf(n, -INF), bffrom(n, -1);
    dbf[0] = 0;
    REP(itr, n-1) {
        REP(i, m) {
            if (chmax(dbf[e[i].to], dbf[e[i].from] + e[i].cost)) {
                bffrom[e[i].to] = e[i].from;
            }
        }
    }
    bool has_halo = false;
    REP(i, m) {
        if (dbf[e[i].from] + e[i].cost > dbf[e[i].to]) {
            has_halo = true;
            break;
        }
    }
    if (has_halo) {
        cout << -1 << endl;
        return 0;
    }
    
    cout << max(dbf[n-1], 0LL) << endl;
    
}

Measured memory_bytes: 896