#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

template<class T = Int>
struct Edge {
	Int from, to;
	T cost;
	Edge() {}
	Edge(Int from, Int to, T cost) : from(from), to(to), cost(cost) {}
};

template<class T>
vector<T> Bellman_Ford(vector<Edge<T>>& edges, Int V, Int st) {//V:ノード数 st:スタート地点

	const T inf = numeric_limits<T>::max(); // different from INF!!!
	vector<T> dist(V, inf);
	dist[st] = 0;
	for (Int i = 0; i < V - 1; i++) {
		for (const auto& e : edges) {
			if (dist[e.from] == inf) continue;//ないとオーバーフローの可能性あり、infの定義次第、つけとくのが無難、ただの枝切りではない
			dist[e.to] = min(dist[e.to], dist[e.from] + e.cost);
		}
	}

	//負閉路探索
	//V-1回目より後に更新があると負閉路が検出されて、そこから1番遠いノードに伝播するまでV-1回かかりうるので追加でV回のループが必要
	for (Int i = 0; i < V; i++) {
		for (const auto& e : edges) {
			if (dist[e.from] == inf) continue;
			if (dist[e.from] == -inf) dist[e.to] = -inf; // src is nloop -> dst is nloop
			else if (dist[e.to] > dist[e.from] + e.cost) dist[e.to] = -inf; // chmin is possible -> nloop
		}
	}

	return dist;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, M, P;
	cin >> N >> M >> P;

	vector<Edge<Int>> edges(M);
	Int a, b, c;
	for (Int i = 0; i < M; i++) {
		cin >> a >> b >> c;
		a--;
		b--;
		c -= P;
		edges[i].from = a;
		edges[i].to = b;
		edges[i].cost = -c;
	}

	vector<Int> ans;
	ans=Bellman_Ford(edges, N, 0);

	if (ans[N - 1] == -numeric_limits<Int>::max()) {
		cout << -1 << "\n";
	}
	else {
		cout << max(0LL,-ans[N - 1]) << "\n";
	}

}

Measured memory_bytes: 384