#include <bits/stdc++.h>
using namespace std;

#define dist2D(x1,y1,x2,y2)         ((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
#define dist3D(x1,y1,z1,x2,y2,z2)   ((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2))
#define EPS                         1e-12
#define endl                        "\n"
#define FastIO                      ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FI                          freopen("in.txt","r",stdin)
#define FO                          freopen("out.txt","w",stdout)
#define fap(x)                      cout<<"WTH: "<<x<<endl
#define ff                          first
#define fof(i,x,y)                  for(int i=x;i<(int)y;i++)
#define fob(i,x,y)                  for(int i=x;i>=(int)y;i--)
#define INF              1000000000000000000
#define ld                          long double
#define ll                          long long
#define mem(x,y)                    memset(x,y,sizeof x)
#define mp                          make_pair
#define msi                         map<string,int>
#define mii                         map<int,int>
#define mis                         map<int,string>
#define MOD                         998244353
#define PI                          acos(-1.0)
#define PQ                          priority_queue
#define pb                          push_back
#define pib                         pair<int,bool>
#define pii                         pair<int,int>
#define pll                         pair<ll,ll>
#define sfi(x)                      scanf("%d",&x)
#define sfii(x,y)                   scanf("%d%d",&x,&y)
#define sfiii(x,y,z)                scanf("%d%d%d",&x,&y,&z)
#define siz(x)                      (int)x.size()
#define sortv(v)                    sort(v.begin(),v.end())
#define ss                          second
#define timeTaken                   endd=clock();cout<<(double)(endd-beginn)/CLOCKS_PER_SEC*1000<<endl
#define timeInit                    clock_t beginn=clock(),endd
#define ull                         unsigned long long
#define umsi                        unordered_map<string,int>
#define umii                        unordered_map<int,int>
#define umis                        unordered_map<int,string>
#define vb                          vector<bool>
#define vi                          vector<int>
#define vvi                         vector<vi>
#define vii                         vector<pii>
#define vvii                        vector<vii>
#define vll                         vector<ll>
#define vvll                        vector<vll>
#define vpll                        vector<pll>


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
        tree_order_statistics_node_update> ordered_set;

//os.order_of_key(v): returns how many elements strictly less than v
//os.find_by_order(k-1): returns kth smallest element's iterator


template<class T> class compare{
public:
    bool operator()(pair<T,T> &x,pair<T,T> &y){
        if(x.first==y.first){
            return x.ss>y.ss;
        }
        return x.ff>y.ff;
    }
};

//template<class T> ostream& operator<<(ostream &os,const pair<T,T> &a) { os<<a.ff<<" "<<a.ss; }
ll power(ll a,int b) {
    ll po = 1;
    while (b) {
        if (b & 1)
            po *= a;
        a *= a;
        b >>= 1;
    }
    return po;
}

template<class T> pair<T,T> operator+(const pair<T,T> &a,const pair<T,T> &b){ return {a.ff+b.ff,a.ss+b.ss}; }
template<class T> pair<T,T> operator-(const pair<T,T> &a,const pair<T,T> &b){ return {a.ff-b.ff,a.ss-b.ss}; }
template<class T> pair<T,T> operator*(const pair<T,T> &a,const pair<T,T> &b){ return {a.ff*b.ff,a.ss*b.ss}; }
template<class T> pair<T,T> operator%(const pair<T,T> &a,const pair<T,T> &b){ return {a.ff%b.ff,a.ss%b.ss}; }
template<class T,class U> pair<T,T> operator+(const pair<T,T> &a,const U &b){ return { a.ff+b,a.ss+b}; }
template<class T,class U> pair<T,T> operator*(const pair<T,T> &a,const U &b){ return { a.ff*b,a.ss*b}; }

int Set(int N,int pos) { return N=N|(1<<pos); }
int reset(int N,int pos){ return N=N&~(1<<pos);}
bool check(int N,int pos){  return (bool) (N&(1<<pos));}

///=======================================template=======================================///


int main()
{
    //FI;//FO;
    FastIO;//timeInit;

    int V,E,source=1,p;
    cin>>V>>E>>p;
    int n=V;

    vvii AdjLst(V+1,vii());
    for(int i=0;i<E;i++){
        int u,v,w;
        cin>>u>>v>>w;
        AdjLst[u].pb(pii(v,w-p));///directed graph....
    }

    vll dist(V+1,INT_MAX);
    dist[source]=0;
    int dir[V+1];
    dir[source]=-1;
    for(int i=1;i<=V-1;i++){///overall O(VE): worst case

        bool flag=false;

        for(int u=1;u<=V;u++){
            int siz=AdjLst[u].size();
            if(dist[u]==INT_MAX)
                continue;

            for(int j=0;j<siz;j++){
                pii v=AdjLst[u][j];
                if(dist[u]-v.second<dist[v.first]){
                    dist[v.first]=dist[u]-v.second;
                    dir[v.first]=u;
                    flag=true;
                }
            }
        }

        if(!flag) break;///breaks if all distances are relaxed maximally
    }

    ///checking if negative cycle exists or not
    bool isNegativeCycle=false,isN=false;

    int ii=n+2;

    while(ii--) {
        for (int i = 1; i <= V; i++) {
            int siz = AdjLst[i].size();
            if (dist[i] == INT_MAX)
                continue;
            for (int j = 0; j < siz; j++) {
                pii v = AdjLst[i][j];

                if (dist[i] - v.second < dist[v.first]) {
                    dist[v.ff] = dist[i] - v.second;
                    isNegativeCycle = true;
                    if (v.ff == n) {
                        isN = true;
                        break;
                    }
                }
            }
            if (isNegativeCycle and isN) break;
        }
    }

    if((isNegativeCycle and isN) or dist[n]==INT_MAX)
    {
        cout<<-1<<endl;
        exit(0);
    }
    else{
        //cout<<dist[n]<<endl;
       cout<<max(0LL,-dist[n])<<endl;
    }


    //timeTaken;
    return 0;
}

Measured memory_bytes: 384