#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define M 2505
#define rint register int
int n,m,p;
int a,b,c;
LL Dis[M];
struct Edge {
	int to,v;
};
bool inQ[M];
int cntTo[M];
vector<Edge>E[M];
vector<int>e[M];
queue<int>Q;
bool Mark[M];
void dfs(int x) {
	Mark[x]=1;
	for(int i=0; i<(int)e[x].size(); ++i)
		if(!Mark[e[x][i]])dfs(e[x][i]);
}
int main() {
	scanf("%d%d%d",&n,&m,&p);
	for(int i=1; i<=m; ++i) {
		scanf("%d%d%d",&a,&b,&c);
		E[a].push_back((Edge)<%b,c-p%>);
		e[b].push_back(a);
	}
	dfs(n);
	for(int i=2; i<=n; ++i)Dis[i]=-1e18;
	Q.push(1);
	bool flag=1;
	while(!Q.empty()) {
		int x=Q.front();
		Q.pop();
		if(++cntTo[x]==n) {
			flag=0;
			break;
		}
		inQ[x]=0;
		for(int i=0; i<(int)E[x].size(); ++i) {
			int u=E[x][i].to,v=E[x][i].v;
			if(!Mark[u])continue;
			if(Dis[u]<Dis[x]+v) {
				Dis[u]=Dis[x]+v;
				if(!inQ[u])Q.push(u),inQ[u]=1;
			}
		}
	}
	printf("%lld",flag?max(0LL,Dis[n]):-1LL);
}