#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
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; }
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << "NO" << endl;return 0
#define MM <<" "<<
#define Endl endl

struct edge{int from,end,cost;};
vector<int> BellmanFord(vector<edge> es, int s){
    int E=es.size();
    int V=0;int dend[3000];
    vector<int> d;
    for(int i=0;i<E;i++){
        V=max(V,es[i].from+1);
        V=max(V,es[i].end+1);
    }
    for(int i=0;i<V;i++)d.push_back(INF);
    d[s]=0;
    for(int j=0;j<V+2;j++){
        
        if(j==V){
            for(int i=0;i<V;i++){
                dend[i]=d[i];
            }
        }
        if(j==V+1){
            bool c=true;
            for(int i=0;i<V;i++){
                if(dend[i]!=d[i]){
                    c=false;
                }
            }
            if(c==false){
                d[V-1]=-INF;
            }
            break;
        }
        
        
        bool update=false;
        for(int i=0;i<E;i++){
            edge k=es[i];
            if(d[k.from]!=INF && d[k.end]>d[k.from]+k.cost){
                d[k.end]=d[k.from]+k.cost;
                update=true;
            }
        }
        if(!update)break;
    }
    return d;
}

//struct edge{int from,end,cost;};
vector<int> DFS(vector<edge> G,int s){
    int M=G.size();
    int N=0;
    vector<bool> already;
    vector<int> R;
    queue<int> P;
    vector<vector<pair<int,int>>> E;
    for(int i=0;i<M;i++){
        N=max(N,G[i].from);
        N=max(N,G[i].end);
    }
    N++;
    for(int i=0;i<N;i++){
        E.push_back({{0,0}});
    }
    for(int i=0;i<N;i++){
        already.push_back(false);
        R.push_back(INF);
    }
    for(int i=0;i<M;i++){
        E[G[i].from].push_back({G[i].end,G[i].cost});
    }
    R[s]=0;
    P.push(s);
    while(!P.empty()){
        int t = P.front();
        P.pop();
        if(already[t]){
            continue;
        }
        already[t]=true;
        for(int i=0;i<E[t].size();i++){
            R[E[t][i].first]=min(R[E[t][i].first],R[t]+E[t][i].second);
            P.push(E[t][i].first);
        }
    }
    return R;
}

signed main(void){
    int N,M,P;
    int A[5141],B[5141],C[5141];
    cin >> N >> M >> P;
    REP(i,M){
        cin >> A[i] >> B[i] >> C[i];
        A[i]--;B[i]--;
    }
    
    edge h;
    vector<edge> D,F;
    vector<int> G,H;
    REP(i,M){
        h.from=A[i];
        h.end=B[i];
        h.cost=C[i]-P;
        D.push_back(h);
    }
    REP(i,M){
        h.from=B[i];
        h.end=A[i];
        h.cost=C[i]-P;
        F.push_back(h);
    }
    G=DFS(D,0);
    H=DFS(F,N-1);
    
    vector<edge> es;
    int now=0;
    REP(i,M){
        h.from=A[i];
        h.end=B[i];
        h.cost=-C[i]+P;
        if(G[A[i]]!=INF &&G[B[i]]!=INF && H[A[i]]!=INF&& H[B[i]]!=INF){
            es.push_back(h);
            now++;
        }
    }
    vector<int> d;
    d= BellmanFord(es,0);
    if(d[N-1]==-INF){
        cout << -1 << endl;
    }else{
        cout << max(-d[N-1],0ll) << endl;
    }
    return 0;
}


Measured memory_bytes: 1200