#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

struct Edge {
    ll from, to, cost;
    Edge() {}
    Edge(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}
};

bool bellman_ford_strict(int s, int V, vector<ll> &dp, const vector<Edge> &g) {
    bool neg_loop = false;
    dp[s] = 0;
    for (int i = 0; i < V; ++i) {
        bool update = false;
        for (auto &&e:g) {
            if (dp[e.to]>dp[e.from]+e.cost) {
                dp[e.to]=dp[e.from]+e.cost;
                update=true;
            }
        }
        if (!update) break;
        if (i==V-1) {
            neg_loop=true;
            break;
        }
    }
    return neg_loop;
}

int main(int argc, char const *argv[]) {
    ll n,m,p; cin>>n>>m>>p;
    vector<ll> A(m),B(m),C(m);
    vector<vector<int>> bg(n), cg(n);
    rep(i,m) {
        ll a,b,c; cin>>a>>b>>c;
        --a,--b; c-=p;
        A[i] = a; B[i] = b; C[i] = -c;
        bg[a].push_back(b);
        cg[b].push_back(a);
    }

    vector<bool> exs(n),ext(n),ex(n);

    auto bfs = [&] (int start, int goal, const vector<vector<int>> &gg, vector<bool> &exist) {
        queue<int> q;
        q.push(start);
        vector<int> dp(n,INF);
        dp[start] = 0;
        while (q.size()) {
            int v = q.front(); q.pop();
            for (auto &&e: gg[v]) {
                if (dp[e] > dp[v]+1) {
                    dp[e] = dp[v]+1;
                    q.push(e);
                }
            }
        }
        rep(i,n) if (dp[i]!=INF) exist[i] = true;
        return;
    };

    bfs(0,n-1,bg,exs);
    bfs(n-1,0,cg,ext);

    rep(i,n) ex[i] = exs[i]&ext[i];

    vector<Edge> g;
    rep(i,m) {
        if (ex[A[i]]&&ex[B[i]]) {
            g.emplace_back(A[i],B[i],C[i]);
        }
    }

    vector<ll> dp(n,LINF);
    bool neg = bellman_ford_strict(0,n,dp,g);

    if (neg) cout << -1 << '\n';
    else cout << max(-dp[n-1],0ll) << '\n';

    return 0;
}

Measured memory_bytes: 896