#include "bits/stdc++.h"
using namespace std;

struct edge {
	long long from;
	long long to;
	long long cost;
};

int main() {
	long long N, M, P, INF = 1000000000;
	static long long Dist[2500] = {};
	bool visitA[2500] = {}, visitB[2500] = {};
	vector<edge> VE;
	cin >> N >> M >> P;
	visitA[0] = true;
	visitB[N - 1] = true;
	for (int i = 0; i < N; i++) Dist[i] = INF;
	Dist[0] = 0;
	for (int i = 0; i < M; i++) {
		long long A, B, C;
		cin >> A >> B >> C;
		A--, B--;
		edge NE;
		NE.from = A, NE.to = B, NE.cost = P-C;
		VE.push_back(NE);
	}
	for (int i = 0; i < N; i++) {
		for (edge E : VE) {
			if (visitA[E.from]) visitA[E.to] = true;
			if (visitB[E.to]) visitB[E.from] = true;
		}
	}
	for (int i = 0; i < N; i++) {
		for (edge E : VE) {
			if (Dist[E.to] > Dist[E.from] + E.cost) {
				Dist[E.to] = Dist[E.from] + E.cost;
				if (i == N - 1 && visitA[E.from] && visitA[E.to] && visitB[E.from] && visitB[E.to]) {
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}
	cout << max(0LL, -Dist[N - 1]) << endl;
}
