#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

const ll INF = 1LL << 60;

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

int main() {
  int n, m, p;
	cin >> n >> m >> p;
	vector<Edge> g(m);
	rep(i, m) {
		cin >> g[i].from >> g[i].to >> g[i].cost;
		g[i].from--, g[i].to--;
		g[i].cost = p - g[i].cost;
	}
	
	vector<ll> ans(n, INF);
	ans[0] = 0;
	rep(i, n) {
		rep(j, m) {
			Edge e = g[j];
			if (ans[e.from] == INF) continue;
			if (ans[e.from] + e.cost < ans[e.to]) {
				ans[e.to] = ans[e.from] + e.cost;
			}
		}
	}
	
	vector<bool> neg(n, false);
	rep(i, n) {
		rep(j, m) {
			Edge e = g[j];
			if (ans[e.from] == INF) continue;
			if (ans[e.from] + e.cost < ans[e.to]) {
				ans[e.to] = ans[e.from] + e.cost;
				neg[e.to] = true;
			}
			if (neg[e.from]) neg[e.to] = true;
		}
	}
	
	if (neg[n - 1]) cout << -1 << endl;
	else if (ans[n - 1] < 0) cout << -ans[n - 1] << endl;
	else cout << 0 << endl;
	return 0;
}
