#include <vector>
#include <math.h>
#include <string>
#include <ios>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <iterator>
#define INFINIT_LL 0x7F00000000000000
#define LL long long
using namespace std;
typedef struct Edge {
	LL from;
	LL to;
	LL cost;
	bool use;
};

vector<Edge> dfs(LL start_point,vector<Edge> edges) {
	vector<LL> search_stack;
	vector<LL> searched_list;

	search_stack.push_back(start_point);
	while (search_stack.size() != 0) {
		LL current_point = search_stack.back();
		search_stack.pop_back();

		searched_list.push_back(current_point);
		vector<LL> next_points;
		for (Edge e : edges) {
			if (e.from == current_point) {
				next_points.push_back(e.to);
			}
		}

		for (LL next_point : next_points) {
			auto itr = find(searched_list.begin(), searched_list.end(), next_point);
			if (itr != searched_list.end()) {
				continue;
			}
			
			itr = find(search_stack.begin(), search_stack.end(), next_point);
			if (itr != search_stack.end()) {
				continue;
			}

			search_stack.push_back(next_point);
		}
	}

	vector<Edge> ret;
	int use_ids[10000] = {};
	for (LL from_to : searched_list) {
		int i = 0;
		for (Edge e : edges) {
			if (from_to == e.from || from_to == e.to) {
				use_ids[i]=1;
			}
			i++;
		}
	}

	int i = 0;
	for (Edge e : edges) {
		if (use_ids[i]) {
			ret.push_back(e);
		}
		i++;
	}
	return ret;
}

vector<Edge> dfs_back(LL start_point, vector<Edge> edges) {
	vector<LL> search_stack;
	vector<LL> searched_list;

	search_stack.push_back(start_point);
	while (search_stack.size() != 0) {
		LL current_point = search_stack.back();
		search_stack.pop_back();

		searched_list.push_back(current_point);
		vector<LL> next_points;
		for (Edge e : edges) {
			if (e.to == current_point) {
				next_points.push_back(e.from);
			}
		}

		for (LL next_point : next_points) {
			auto itr = find(searched_list.begin(), searched_list.end(), next_point);
			if (itr != searched_list.end()) {
				continue;
			}

			itr = find(search_stack.begin(), search_stack.end(), next_point);
			if (itr != search_stack.end()) {
				continue;
			}

			search_stack.push_back(next_point);
		}
	}

	vector<Edge> ret;
	int use_ids[10000] = {};
	for (LL from_to : searched_list) {
		int i = 0;
		for (Edge e : edges) {
			if (from_to == e.from || from_to == e.to) {
				use_ids[i] = 1;
			}
			i++;
		}
	}

	int i = 0;
	for (Edge e : edges) {
		if (use_ids[i]) {
			ret.push_back(e);
		}
		i++;
	}

	return ret;
}

int main() {
	LL N,M,	P;
	cin >> N >> M >> P;
	
	LL res = 0;
	vector<Edge> edge(M);
	vector<LL> min_gain(N);

	for (int m = 0; m < M; m++) {
		cin >> edge[m].from;
		cin >> edge[m].to;
		cin >> edge[m].cost;
		edge[m].from--;
		edge[m].to--;
		edge[m].cost = -(edge[m].cost - P);
	}
	
	for (int i = 0; i < N; i++) {
		min_gain[i] = INFINIT_LL;
	}
	min_gain[0] = 0;

	edge = dfs(0,edge);
	edge = dfs_back(N-1, edge);

	for (int n = 0; n < N; n++) {
		for (int m = 0; m < edge.size(); m++) {
			if (min_gain[edge[m].to] > min_gain[edge[m].from] + edge[m].cost) {
				min_gain[edge[m].to] = min_gain[edge[m].from] + edge[m].cost;
				if (n == N- 1) {
					cout << -1;
					return 0;
				}
			}
		}
	}

	cout << max((LL)(0),-min_gain[N-1]);

	return 0;
}

Measured memory_bytes: 1084