#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9+10;
const ll inf_l = 1e18;
const int MAX = 1e5;

template<class T>
struct bellman_ford {
    struct edge {
        int to;
        T cost;
    };
    vector<vector<edge>> G;
    vector<vector<edge>> G_rev;
    vector<T> dis;
    vector<T> dis_middle;
    int V;
    T init_v;
    bool negative_loop;

    bellman_ford(int n, T init) : G(n), G_rev(n), dis(n,init), 
        V(n), init_v(init) {}
    void add_edge(int a, int b, T cost) {
        G[a].push_back(edge{b,cost});
        G_rev[b].push_back(edge{a,cost});
    }
    void run(int s) {
        bool update = false;
        dis[s] = 0;
        for (int i = 0; i < V; i++) {
            if (i == V - 1) dis_middle = dis;
            for (int from = 0; from < V; from++) {
                if (dis[from] == init_v) continue;
                for (auto e : G[from]) {
                    if (dis[e.to] > dis[from] + e.cost) {
                        dis[e.to] = dis[from] + e.cost;
                        if (i == V - 1) update = true;
                    }
                }
            }
        }
        negative_loop = update;
    }
    T path(int s, int t) {
        if (!negative_loop) return dis[t];
        else {
            auto can_reach_from_start = can_reach(G,s);
            auto can_reach_from_goal = can_reach(G_rev,t);
            for (int i = 0; i < V; i++) {
                if (can_reach_from_start[i] && can_reach_from_goal[i]) {
                    if (dis_middle[i] != dis[i]) {
                        return -init_v;
                    }
                }
            }
            return dis[t];
        }
    }
    vector<bool> can_reach(const vector<vector<edge>> &G, int s) {
        vector<bool> res(V,false);
        queue<int> q;
        q.push(s);
        res[s] = true;
        while (!q.empty()) {
            int v = q.front(); q.pop();
            for (auto n_v : G[v]) {
                if (res[n_v.to] == false) {
                    q.push(n_v.to);
                    res[n_v.to] = true;
                }
            }
        }
        return res;
    }
};

int main() {
    int n, m, p; cin >> n >> m >> p;
    bellman_ford<int> bf(n,inf);
    rep(i,m) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        bf.add_edge(a,b,-c+p);
    }
    bf.run(0);
    int ans = -bf.path(0,n-1);
    printf("%d\n",ans==inf?-1:max(0,ans));
}

Measured memory_bytes: 4012