#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORUL(i,l,u) for(int i=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 0

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

typedef struct Edge {
	int from;
	int to;
	int cost;
} Edge;

bool reachablefrom1[2550];
bool reachablefromN[2550];
bool reachable[2550];

vector<Edge> edges;
vector<int> to[2550];
vector<int> from[2550];

void dfs(int u)
{
	if(reachablefrom1[u]) {
		return;
	}
	reachablefrom1[u] = true;
	for(int v : to[u]) {
		dfs(v);		
	}
}
void rdfs(int v)
{
	if(reachablefromN[v]) {
		return;
	}
	reachablefromN[v] = true;
	for(int u : from[v]) {
		rdfs(u);
	}
}

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	int N, M, P;
	cin >> N >> M >> P;
	// clock_t start = clock();
	DOUT << "start resizing"<<endl;

	DOUT << "start initializing vertices"<<endl;

	DOUT << "start adding edges"<<endl;

	FOR(m,M) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;b--;
		Edge e = { a, b, -(c-P) };
		DOUT<<"e="<<e.from<<","<<e.to<<","<<e.cost<<endl;

		edges.push_back(e);
		to[a].push_back(b);
		from[b].push_back(a);
	}
	// clock_t point1 = clock();
	dfs(0);
	rdfs(N-1);
	FOR(n,N) {
		DOUT << "reachablefrom1["<<n<<"]="<<reachablefrom1[n]<<endl;
		DOUT << "reachablefromN["<<n<<"]="<<reachablefromN[n]<<endl;
		reachable[n] = reachablefrom1[n]&&reachablefromN[n];
	}

	// clock_t point2 = clock();
	int updated_count = 0;

	vector<int> costs(N,INT_MAX);
	{
		costs[0]=0;
		while(true) {
			bool updated = false;
			FOR(m,M) {
				Edge e = edges[m];
				int a = e.from;
				int b = e.to;
				int c = e.cost;
				DOUT << "m="<<m<<endl;
				DOUT << "costs["<<b<<"]=="<<b<<endl;
				DOUT << "costs["<<a<<"]=="<<a<<endl;
				DOUT << "edges["<<m<<"].cost="<<c<<endl;
				DOUT << "reachable["<<m<<"]="<<reachable[m]<<endl;
				if (!reachable[a]) {
					continue;
				}
				if (!reachable[b]) {
					continue;
				}
				if (costs[a]==INT_MAX) {
					continue;
				}
				int nc = costs[a] + c;
				if(costs[b]>nc) {
					costs[b] = nc;
					DOUT<<"UPDATED:"<<"costs["<<edges[m].to<<"]=="<<edges[m].cost<<endl;
					updated = true;
				}
			}
			if(!updated) {
				break;
			}
			updated_count++;
			DOUT << "updated_count="<<updated_count<<endl;
			DOUT << "==="<<endl;
			if(updated_count>N) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	// clock_t point3 = clock();
	DOUT << "updated_count="<<updated_count<<endl;
	DOUT << "==="<<endl;
	DOUT << "-costs["<<N-1<<"]="<<-costs[N-1]<<endl;
	cout << max(0,-costs[N-1])<<endl;

	// cout << "point1="<<(double)(point1-start)<<endl;
	// cout << "point2="<<(double)(point2-start)<<endl;
	// cout << "point3="<<(double)(point3-start)<<endl;
	return 0;
}



Measured memory_bytes: 640