// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <utility>

#include <queue>

using namespace std;

typedef long long ll;



const int INF = 1000000000;



int main()

{

    int n, m, p;

    cin >> n >> m >> p;

    ll a[5002], b[5002], c[5002];

    vector<int> rev[5002];

    for(int i = 0; i < m; i++){

        cin >> a[i] >> b[i] >> c[i];

        rev[b[i]].push_back(a[i]);

        c[i] -= p;

    }

    bool arrival[2502];

    for(int i = 1; i <= n; i++) arrival[i] = false;

    arrival[n] = true;

    queue<int> que;

    que.push(n);

    while(!que.empty()){

        int now = que.front();

        que.pop();

        for(int next : rev[now]){

            if(!arrival[next]){

                arrival[next] = true;

                que.push(next);

            }

        }

    }

    ll d[2502];

    for(int i = 1; i <= n; i++) d[i] = -INF;

    d[1] = 0;

    for(int i = 0; i < n; i++){

        for(int j = 0; j < m; j++){

            if(d[a[j]] != -INF && d[b[j]] < d[a[j]] + c[j]) d[b[j]] = d[a[j]] + c[j];

        }

    }

    ll memo[2502];

    for(int i = 1; i <= n; i++){

        memo[i] = d[i];

    }

    for(int i = 0; i < n; i++){

        for(int j = 0; j < m; j++){

            if(d[a[j]] != -INF && d[b[j]] < d[a[j]] + c[j]) d[b[j]] = d[a[j]] + c[j];

        }

    }

    bool inf = false;

    for(int i = 1; i <= n; i++){

        if(d[i] != memo[i] && arrival[i]) inf = true;

    }

    ll zero = 0;

    if(inf) cout << -1 << endl;

    else cout << max(d[n], zero) << endl;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <queue>

using namespace std;

typedef long long ll;



const ll INF = 10000000000000009;



template <typename T>

struct Edge

{

    int to;

    T cost;

};



template <typename T>

struct WeightedGraph

{

    int n;

    vector<vector<Edge<T>>> g;

    

    WeightedGraph(int n) : n(n){

        g.resize(n);

    }

    

    void init(int n_){

        n = n_;

        g.resize(n_);

    }

    

    void add_edge(int from, int to, T cost){

        g[from].push_back((Edge<T>){to, cost});

    }

};



int main()

{

    int n, m;

    ll p;

    cin >> n >> m >> p;

    WeightedGraph<ll> g(n), h(n);

    for(int i = 0; i < m; i++){

        int a, b;

        ll c;

        cin >> a >> b >> c;

        a--; b--;

        g.add_edge(a, b, c - p);

        h.add_edge(b, a, 1);

    }

    ll d[2503], l[2503], r[2503];

    for(int u = 0; u < n; u++) d[u] = l[u] = r[u] = -INF;

    d[0] = 0;

    for(int i = 1; i <= n * 2; i++){

        for(int u = 0; u < n; u++){

            if(d[u] == -INF) continue;

            for(Edge<ll> e : g.g[u]){

                int v = e.to;

                d[v] = max(d[v], d[u] + e.cost);

            }

        }

        if(i == n){

            for(int u = 0; u < n; u++) l[u] = d[u];

        }

    }

    bool b[2503]{0};

    b[n - 1] = true;

    queue<int> que;

    que.push(n - 1);

    while(que.size()){

        int u = que.front();

        que.pop();

        for(Edge<ll> e : h.g[u]){

            int v = e.to;

            if(!b[v]){

                b[v] = true;

                que.push(v);

            }

        }

    }

    for(int u = 0; u < n; u++){

        if(d[u] > l[u] && b[u]){

            cout << -1 << endl;

            return 0;

        }

    }

    cout << max(l[n - 1], 0ll) << endl;

}


// Fastest known solution for this problem: