#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Edge {
	int src;
	int dst;
	int cost;
};

int main()
{
	int N, M, P;
	cin >> N >> M >> P;

	vector<vector<Edge>> g(N);

	for (int i = 0; i < M; ++i) {
		int A, B, C;
		cin >> A >> B >> C;
		--A;
		--B;
		Edge e;
		e.src = A;
		e.dst = B;
		e.cost = P - C;
		g[A].push_back(e);
	}

	const long long INF = 1LL << 60;
	vector<long long> d(N,INF);
	d[0] = 0;

	for (int k = 0; k < 4 * N; ++k) {
		for (const auto &edges : g) {
			for (const auto &e : edges) {
				d[e.dst] = min(d[e.dst], d[e.src] + e.cost);
			}
		}
	}

	long long ans1 = -d[N - 1];

	for (int k = 0; k < 4 * N; ++k) {
		for (const auto &edges : g) {
			for (const auto &e : edges) {
				d[e.dst] = min(d[e.dst], d[e.src] + e.cost);
			}
		}
	}

	long long ans2 = -d[N - 1];

	if (ans2 > ans1) {
		cout << -1 << endl;
	}
	else if (ans2 < 0) {
		cout << 0 << endl;
	}
	else {
		cout << ans2 << endl;
	}
}
