#include<bits/stdc++.h>
#define N 2505
using namespace std;
int n,m,K;
vector<int>P[N],C[N],T[N];
int vis[N];
long long dis[N];
int inu[N];
int mark[N];
void dfs(int p){
	mark[p]=1;
	for(int i=0;i<T[p].size();i++){
		int y=T[p][i];
		if(mark[y])continue;
		dfs(y);
	}
}
void spfa(){
	queue<int>Q;
	for(int i=1;i<=n;i++)dis[i]=0x8f8f8f8f8f8f8f8f,inu[i]=0;
	Q.push(1);dis[1]=0,vis[1]=1,inu[1]=1;
	int cnt=0;
	while(!Q.empty()){
		int v=Q.front();
		Q.pop();
		vis[v]=0;
		if(inu[v]==n){
			if(mark[v]){
				puts("-1");
				return;
			}else continue;
		}
		for(int i=0;i<(int)P[v].size();i++){
			int y=P[v][i];
			if(dis[v]+C[v][i]>dis[y]){
				dis[y]=dis[v]+C[v][i];
				if(!vis[y])Q.push(y),vis[y]=1,inu[y]++;
			}
		}
	}
	printf("%lld\n",max(0LL,dis[n]));
}
void solve(){
	scanf("%d %d %d",&n,&m,&K);
	for(int a,b,c,i=1;i<=m;i++){
		scanf("%d %d %d",&a,&b,&c);
		c-=K;
		P[a].push_back(b);
		C[a].push_back(c);
		T[b].push_back(a);
	}
	dfs(n);
	spfa();
}
int main (){
	solve();
	return 0;
}