//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

const int MOD = 1e9 + 7;
const ll INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

#define MV 10000

struct edge { int to, cost; };
vector <edge> G[MV];

int V, E;
int d[MV + 1];//最短径路を格納
bool ign[100010], reach[100010], reach2[100010];
bool bellmanford(int s) {
	fill(d, d + MV, INF);
	d[s] = 0;
	int c = 0;
	bool upd = false;
	while (true) {
		upd = false;
		for (int i = 0; i <= V; i++) {
			for (int j = 0; j < G[i].size(); j++) {
				edge e = G[i][j];
				if (ign[e.to])continue;
				if (d[i] != INF && d[e.to] > d[i] + e.cost) {
					d[e.to] = d[i] + e.cost;
					upd = true;
				}
			}
		}
		if (!upd)
			break;
		if (c == V - 1)
			return true;//負の閉路の判定
		c++;
	}
	return false;
}
bool vis[5050], vis2[5050];
bool check1(int s,int n, int g) {
	vis[n] = true;
	if (reach[s])return true;
	if (n == g) {
		reach[n] = true;
		return true;
	}
	bool ok = false;
	for (auto e : G[n]) {
		int nx = e.to;
		if (vis[nx])continue;
		if (check1(s,nx,g)) {
			reach[n] = true;
			return true;
		}
	}
	return false;
}
bool check2(int s, int n, int g) {
	vis2[n] = true;
	if (reach2[n])return true;
	if (n == g) {
		reach2[n] = true;
		return true;
	}
	bool ok = false;
	for (auto e : G[n]) {
		int nx = e.to;
		if (vis2[nx])continue;
		if (check1(s, nx, g)) {
			reach2[n] = true;
			return true;
		}
	}
	return false;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int P;
	d[MV] = INF + 10;
	int first=1;
	bool flag;
	cin >> V >> E >> P;
	for (int i = 0; i < E; i++) {
		int f, t;
		edge e;
		cin >> f >> e.to >> e.cost;
		e.cost -= P;
		e.cost *= -1;
		G[f].push_back(e);
		/*
		G[f]にはfからでてる辺が格納されている。
		*/
		t = e.to;

		//e.to = f;
		//G[t].push_back(e);
	}
	FOR(i, 1, V) {
		fill(vis, vis + V + 1, 0);
		fill(vis2, vis2 + V + 1, 0);
		if (!check1(i, i, V)||!check2(1,1,i)) {
			ign[i] = true;
			//print(i);
		}
	}


	flag = bellmanford(first);
	if (flag) {
		cout << -1 << endl;
		return 0;
	}
	if (d[V] >= INF) {
		cout << "-1" << endl;
	}
	else {
		cout << max((ll)0,-d[V]) << endl;
	}
 }



Measured memory_bytes: 768