#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>
#include<unordered_map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
#define int long long
typedef pair<int,int> P;
const int inf=1e9+7;
const int MOD=1000000007;

struct Node{
  int no;
  int col;
  long long dist;
  bool comp;
  vector<pair<Node*,long long>> child;
  vector<pair<Node*,long long>> par;
  void build(int i){
    no=i;col=0;dist=-inf;
    comp=false;
  }
};
bool operator >(const Node &a,const Node &r){
        return a.dist < r.dist;
    }
struct Graph{
    int n;
    bool direct;
    vector<Node> node;
    unordered_map<int,int> dict;
    Graph(int N){
        n=N;
        node.resize(n+1);
        for(int i=1;i<=n;++i){
            node[i].build(i);
        }
    }
    void input(int m,bool flag,int p){
        direct=flag;
        map<P,int> memo;
        for(int i=0;i<m;++i){
            int l;
            int a,b;cin>>a>>b>>l;
            P buf={a,b};
            l-=p;
            auto it=memo.find(buf);
            if(it==memo.end()||memo[buf]<l){
                memo[buf]=l;
            }
        }
        for(const auto& it:memo){
            int a=it.first.first;
            int b=it.first.second;
            int l=it.second;
            node[a].child.push_back({&node[b],l});
            node[b].par.push_back({&node[a],l});
        }
    }
    void DFS(int s){
        queue<Node> que;
        que.push(node[s]);
        dict[s]=2;
        while(!que.empty()){
            Node buf=que.front();que.pop();
            int num=buf.par.size();
            rep(i,num){
                if(dict[buf.par[i].first->no]==2)continue;
                dict[buf.par[i].first->no]=2;
                que.push(*buf.par[i].first);
            }
        }
        que.push(node[1]);
        dict[1]=1;
        while(!que.empty()){
            Node buf=que.front();que.pop();
            int num=buf.child.size();
            rep(i,num){
                if(dict[buf.child[i].first->no]==1)continue;
                if(dict[buf.child[i].first->no]==2){
                    dict[buf.child[i].first->no]=1;
                    que.push(*buf.child[i].first);
                }
            }
        }
    }
    bool Bellman_ford(int s){
        vector<pair<P,int>> edges;
        int v=0;
        rep1(i,n){
            if(dict[i]!=1){
                continue;
            }
            ++v;
            int num=node[i].child.size();
            rep(j,num){
                edges.push_back({{i,node[i].child[j].first->no},node[i].child[j].second});
            }
        }
        int e=edges.size();
        node[s].dist=0;
        int cur=0;
        rep1(i,n){
            if(dict[i]==0)continue;
            ++cur;
            rep(j,e){
                pair<P,int> buf=edges[j];
                if(node[buf.first.second].dist<node[buf.first.first].dist+buf.second){
                    node[buf.first.second].dist=node[buf.first.first].dist+buf.second;
                    if(cur==v){
                        return false;
                    }
                }
            }
        }
        return true;
    }
};

signed main(){
    int n,m,p;cin>>n>>m>>p;
    Graph g(n);
    g.input(m,true,p);
    g.DFS(n);
    int res=-inf;
    if(g.Bellman_ford(1)){
        res=g.node[n].dist;
    }
    else{
        cout<<-1<<"\n";
        return 0;
    }
    if(res<0)res=0;
    cout<<res<<"\n";
    return 0;
}


Measured memory_bytes: 1280