#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;


// http://sesenosannko.hatenablog.com/entry/2017/09/01/214852
struct Bellman_Ford{ // 0-index
	struct edge{ll from, to, cost;};
	ll inf = 1e16;
	vector<edge> es;
	vector<ll> d;
	vector<vector<ll>> to,ot;
	vector<bool> okFromG,okFromS;
	ll V,E;
	Bellman_Ford(ll v){init(v);}
	void init(ll v){
		V = v;
		d.resize(V);
		to.resize(V);
		ot.resize(V);
		okFromG.resize(V,false);
		okFromS.resize(V,false);
	}
	void make_edge(ll f,ll t,ll c){
		es.push_back({f,t,c});
		to[f].push_back(t);
		ot[t].push_back(f);
	}
	void rdfs(ll v){
		if(okFromG[v])return;
		okFromG[v] = true;
		for(auto u:ot[v]){
			rdfs(u);
		}
	}
	void dfs(ll v){
		if(okFromS[v])return;
		okFromS[v] = true;
		for(auto u:to[v]){
			dfs(u);
		}
	}
	void rebuilding(ll s,ll g){
		dfs(s);rdfs(g);
		vector<edge> Newes;
		for(edge e:es){
			if((not okFromS[e.from])||(not okFromS[e.to]))continue;
			if((not okFromG[e.from])||(not okFromG[e.to]))continue;
			Newes.push_back(e);
		}
		es = Newes;
	}
	void shortest_path(ll s){
		FOR(i,0,V) d[i] = inf;
		d[s] = 0;
		E = es.size();
		FOR(i,0,V){
			FOR(j,0,E){
				edge e = es[j];
				if(d[e.from]!=inf && d[e.to]>d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
				}
			}
		}
	}
	bool find_negative_loop(){// all graph
		FOR(i,0,V)d[i] = 0;
		E = es.size();
		FOR(i,0,V){
			FOR(j,0,E){
				edge e = es[j];
				if(d[e.to]>d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
					if(i == V-1) return true;
				}
			}
		}
		return false;
	}
	bool find_negative_loop(ll s){// from s
		ll cnt = 0;
		FOR(i,0,V)d[i]=inf;
		d[s]=0;
		E = es.size();
		while(true){
			bool update = false;
			cnt++;
			FOR(i,0,E){
				edge e = es[i];
				if(d[e.from] != inf && d[e.to]>d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
					if(cnt == V){
						return true;
					}
					update = true;
				}
			}
			if(! update)break;
		}
		return false;
	}
	bool shortest_path(int s, int t){ // t: destination
		FOR(i,0,V)d[i] = inf;
		d[s] = 0;
		E = es.size();
		FOR(i,0,2*V){
			FOR(j,0,E){
				edge e = es[j];
				if(d[e.from]!=inf && d[e.to]>d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
					if(i>=V-1 && e.to==t) return true;
				}
			}
		}   
		return false;
	}
};


 
int main(){
	ll V,E,p;
	cin >> V >> E >> p;
	Bellman_Ford bf(V);
	FOR(i,0,E){
		ll a,b,c;
		cin >> a >> b >> c;
		bf.make_edge(a-1,b-1,p-c);
	}
	bf.rebuilding(0LL,V-1);
	if(bf.find_negative_loop(0)){
		cout << -1 << endl;
	}else{
		cout << max(-bf.d[V-1],0LL) << endl;
	}
}

Measured memory_bytes: 1024