#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define nmax_def 220000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

class Graph_class {
public:
	bool graph_from1 = true;
	bool graph_tree = false;
	bool graph_weight = true;
	bool graph_digraph = true;
	int Vnum;
	int Enum;
	ll P;
	vector<pii> edgelist;
	vl edgeweight;
	vector<vi> adjlist;
	vector<vi> adjlist_inv;
	vi adjnum;
	vi adjnum_inv;

	vb is_on_path;

	vi adj_to_root;
	vector<int> DP;
	vi vlist_from_root;
	vl xdist;

	vb x_visited;
	deque<int> x_que;

	void read_edge();
	void adjini();
	void visited_ini();
	void graph_BFS(ll BFS_ini);
	void graph_BFS_inv(ll BFS_ini);
	bool Bellman_Ford(int x);
	void solve();

	bool xydist_def = false;
};

// ----- graph -----

void Graph_class::read_edge() {
	cin >> Vnum;
	if (graph_tree)
		Enum = Vnum - 1;// graph
	else
		cin >> Enum;
	edgelist.resize(Enum);
	edgeweight.resize(Enum, 1);
	cin >> P;
	rep(i, Enum) {
		if (graph_weight)
			cin >> edgelist[i].first >> edgelist[i].second >> edgeweight[i];
		else
			cin >> edgelist[i].first >> edgelist[i].second;
		if (graph_from1) {
			edgelist[i].first--;
			edgelist[i].second--;
		}
		edgeweight[i] = P - edgeweight[i]; // 失点
	}
	return;
}

void Graph_class::adjini() {
	adjnum.resize(Vnum);
	adjnum_inv.resize(Vnum);
	xdist.resize(Vnum, -1);
	adjlist.resize(Vnum);
	adjlist_inv.resize(Vnum);
	adj_to_root.resize(Vnum, -1);
	DP.resize(Vnum, 0);

	is_on_path.resize(Vnum, true);
	rep(i, Vnum)
		adjnum[i] = 0;
	rep(i, Enum) {
		int x = edgelist[i].first;
		int y = edgelist[i].second;
		adjlist[x].push_back(y); // 辺の向きと同じ
		adjlist_inv[y].push_back(x); // 辺の向きと逆
		adjnum[x]++;
		adjnum_inv[y]++;
	}
	x_visited.resize(Vnum);
	visited_ini();

	return;
}

void Graph_class::visited_ini() {
	rep(i, Vnum) {
		x_visited[i] = false;
		adj_to_root[i] = -1;
	}
	x_que.clear();
}

void Graph_class::graph_BFS(ll BFS_ini) {
	visited_ini();
	x_que.push_back(BFS_ini);
	x_visited[BFS_ini] = true;

	// option
	xdist[BFS_ini] = 0;
	vlist_from_root.clear();
	vlist_from_root.push_back(BFS_ini);
	//cout << BFS_ini << endl;
	while (!x_que.empty()) {
		int x = x_que.front();
		x_que.pop_front();
		rep(i, adjnum[x]) {
			int x_new = adjlist[x][i];
			if (!x_visited[x_new]) {
				x_visited[x_new] = true;
				x_que.push_back(x_new);
			}
		}
	}
	return;
}

void Graph_class::graph_BFS_inv(ll BFS_ini) {
	visited_ini();
	x_que.push_back(BFS_ini);
	x_visited[BFS_ini] = true;

	// option
	xdist[BFS_ini] = 0;
	vlist_from_root.clear();
	vlist_from_root.push_back(BFS_ini);
	//cout << BFS_ini << endl;
	while (!x_que.empty()) {
		int x = x_que.front();
		x_que.pop_front();
		rep(i, adjnum_inv[x]) {
			int x_new = adjlist_inv[x][i];
			if (!x_visited[x_new]) {
				x_visited[x_new] = true;
				x_que.push_back(x_new);
			}
		}
	}
	return;
}

bool Graph_class::Bellman_Ford(int x) {
	ll max_tmp = pow(10, 18) * 4;
	rep(i, Vnum)
		xdist[i] = max_tmp;
	xdist[x] = 0;
	rep(xtmp, Vnum) {
		rep(etmp, Enum) {
			ll weighttmp = edgeweight[etmp];
			int x_from = edgelist[etmp].first;
			int x_to = edgelist[etmp].second;
			if (xdist[x_to] > xdist[x_from] + weighttmp) {
				xdist[x_to] = xdist[x_from] + weighttmp;
				//if (i == Vnum - 1)
					//return true;
			}
		}
	}

	// 閉路検出
	rep(xtmp, Vnum + 10) {
		rep(etmp, Enum) {
			ll weighttmp = edgeweight[etmp];
			int x_from = edgelist[etmp].first;
			int x_to = edgelist[etmp].second;
			if (xdist[x_to] > xdist[x_from] + weighttmp) {
				xdist[x_to] = xdist[x_from] + weighttmp;
				if (is_on_path[x_to])
					return true;
			}
		}
	}
	return false;
}

void Graph_class::solve() {
	graph_BFS(0);
	rep(i, Vnum)
		is_on_path[i] = is_on_path[i] & x_visited[i];
	graph_BFS_inv(Vnum - 1);
	rep(i, Vnum)
		is_on_path[i] = is_on_path[i] & x_visited[i];
	ll ans = -1;
	if (!Bellman_Ford(0))
		ans = max(0LL, -xdist[Vnum - 1]); // 失点の符号を反転
	cout << ans << endl;
	return;
}

int main(void) {
	Graph_class graph;
	graph.read_edge();
	graph.adjini();
	graph.solve();
	return 0;
}

Measured memory_bytes: 764