#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <chrono>
#include <random>
#include <numeric>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <climits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <type_traits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define inf 0x3f3f3f3f3f3f3f3f
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) // cerr<<#x<<": "<<x<<endl
#define ll long long
#define ull unsigned long long
using pii = pair<ll, ll>;
#define eps 1e-14
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15) << std::fixed;
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

template <class T>
using vec2 = std::vector<vector<T>>;

//// bit ////
#ifdef _MSC_VER
#ifdef _WIN32
inline unsigned int __builtin_ctz(unsigned int x) { unsigned long r; _BitScanForward(&r, x); return r; }
inline unsigned int __builtin_clz(unsigned int x) { unsigned long r; _BitScanReverse(&r, x); return 31 - r; }
inline unsigned int __builtin_ffs(unsigned int x) { unsigned long r; return _BitScanForward(&r, x) ? r + 1 : 0; }
// inline unsigned int __builtin_popcount(unsigned int x){ return __popcnt(x); }
#ifdef _WIN64
inline unsigned long long __builtin_ctzll(unsigned long long x) { unsigned long r; _BitScanForward64(&r, x); return r; }
inline unsigned long long __builtin_clzll(unsigned long long x) { unsigned long r; _BitScanReverse64(&r, x); return 63 - r; }
inline unsigned long long __builtin_ffsll(unsigned long long x) { unsigned long r; return _BitScanForward64(&r, x) ? r + 1 : 0; }
inline unsigned long long __builtin_popcountll(unsigned long long x) { return __popcnt64(x); }
#else
inline unsigned int hidword(unsigned long long x) { return static_cast<unsigned int>(x >> 32); }
inline unsigned int lodword(unsigned long long x) { return static_cast<unsigned int>(x & 0xFFFFFFFF); }
inline unsigned long long __builtin_ctzll(unsigned long long x) { return lodword(x) ? __builtin_ctz(lodword(x)) : __builtin_ctz(hidword(x)) + 32; }
inline unsigned long long __builtin_clzll(unsigned long long x) { return hidword(x) ? __builtin_clz(hidword(x)) : __builtin_clz(lodword(x)) + 32; }
inline unsigned long long __builtin_ffsll(unsigned long long x) { return lodword(x) ? __builtin_ffs(lodword(x)) : hidword(x) ? __builtin_ffs(hidword(x)) + 32 : 0; }
// inline unsigned long long __builtin_popcountll(unsigned long long x) { return __builtin_popcount(lodword(x)) + __builtin_popcount(hidword(x)); }
#endif // _WIN64
#endif // _WIN32
#endif // _MSC_VER

namespace
{
	struct input_returnner
	{
		ll N;
		input_returnner(ll N_ = 0) : N(N_) {}
		template <typename T>
		operator vector<T>() const
		{
			vector<T> res(N);
			for (auto& a : res)
				cin >> a;
			return std::move(res);
		}
		template <typename T>
		operator T() const
		{
			T res;
			cin >> res;
			return res;
		}
		template <typename T>
		T operator-(T right) { return T(input_returnner()) - right; }
		template <typename T>
		T operator+(T right) { return T(input_returnner()) + right; }
		template <typename T>
		T operator*(T right) { return T(input_returnner())* right; }
		template <typename T>
		T operator/(T right) { return T(input_returnner()) / right; }
		template <typename T>
		T operator<<(T right) { return T(input_returnner()) << right; }
		template <typename T>
		T operator>>(T right) { return T(input_returnner()) >> right; }
	};
	template <typename T>
	input_returnner in() { return in<T>(); }
	input_returnner in() { return input_returnner(); }
	input_returnner in(ll N) { return std::move(input_returnner(N)); }
} // namespace

template <typename T>
istream& operator>>(istream& is, vector<T>& vec)
{
	for (T& x : vec)
		is >> x;
	return is;
}

template <typename T>
struct is_vector : std::false_type
{
};

template <typename T>
struct is_vector<std::vector<T>> : std::true_type
{
};

template <typename T>
constexpr bool is_vector_v = is_vector<T>::value;

template <typename T>
std::ostream& operator<<(std::ostream & out, const std::vector<T> & v)
{
	if (!v.empty())
	{
		for (int i = 0; i < v.size(); ++i)
		{
			out << v[i] << (i == v.size() - 1 ? "\n" : (is_vector_v<T> ? "" : ", "));
		}
	}
	return out;
}

namespace std
{
	// ref: https://stackoverflow.com/questions/7110301/generic-hash-for-tuples-in-unordered-map-unordered-set
	template <class T>
	inline void hash_combine(std::size_t& seed, T const& v)
	{
		seed ^= std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
	}

	// Recursive template code derived from Matthieu M.
	template <class Tuple, size_t Index = std::tuple_size<Tuple>::value - 1>
	struct HashValueImpl
	{
		static void apply(size_t& seed, Tuple const& tuple)
		{
			HashValueImpl<Tuple, Index - 1>::apply(seed, tuple);
			hash_combine(seed, std::get<Index>(tuple));
		}
	};

	template <class Tuple>
	struct HashValueImpl<Tuple, 0>
	{
		static void apply(size_t& seed, Tuple const& tuple)
		{
			hash_combine(seed, std::get<0>(tuple));
		}
	};
	template <typename... TT>
	struct hash<std::tuple<TT...>>
	{
		size_t operator()(std::tuple<TT...> const& tt) const
		{
			size_t seed = 0;
			HashValueImpl<std::tuple<TT...>>::apply(seed, tt);
			return seed;
		}
	};

	template <class T, class U>
	class hash<std::pair<T, U>>
	{
	public:
		size_t operator()(const std::pair<T, U>& x) const
		{
			return hash<std::tuple<T, U>>()(std::tie(x.first, x.second));
		}
	};
} // namespace std

// ref: https://stackoverflow.com/questions/6245735/pretty-print-stdtuple
namespace aux
{
	template <std::size_t...>
	struct seq
	{
	};

	template <std::size_t N, std::size_t... Is>
	struct gen_seq : gen_seq<N - 1, N - 1, Is...>
	{
	};

	template <std::size_t... Is>
	struct gen_seq<0, Is...> : seq<Is...>
	{
	};

	template <class Ch, class Tr, class Tuple, std::size_t... Is>
	void print_tuple(std::basic_ostream<Ch, Tr>& os, Tuple const& t, seq<Is...>)
	{
		using swallow = int[];
		(void)swallow {
			0, (void(os << (Is == 0 ? "" : ", ") << std::get<Is>(t)), 0)...
		};
	}
} // namespace aux

template <class Ch, class Tr, class... Args>
auto operator<<(std::basic_ostream<Ch, Tr> & os, std::tuple<Args...> const& t)
-> std::basic_ostream<Ch, Tr> &
{
	os << "(";
	aux::print_tuple(os, t, aux::gen_seq<sizeof...(Args)>());
	return os << ")";
}

template <class S, class T>
std::ostream& operator<<(std::ostream & os, const std::pair<S, T> & p)
{
	return os << "(" << p.first << ", " << p.second << ")";
}

// ref: https://stackoverflow.com/questions/8542591/c11-reverse-range-based-for-loo�Fp
template <typename T>
struct reversion_wrapper
{
	T& iterable;
};

template <typename T>
auto begin(reversion_wrapper<T> w) { return std::rbegin(w.iterable); }

template <typename T>
auto end(reversion_wrapper<T> w) { return std::rend(w.iterable); }

template <typename T>
reversion_wrapper<T> REV(T && iterable) { return { iterable }; }

template <class T>
bool inside(T left, T val, T right)
{
	return left <= val and val < right;
}

template <class T>
T bitCount(T num)
{
	T res = 0;
	while (num > 0)
	{
		if (num & 1)
			++res;
		num >>= 1;
	}
	return res;
}

ll MOD = 1e9 + 7;
//ll MOD = 998244353;

void solve();

signed main()
{
	SETUP;
#ifdef _DEBUG
	while (true)
	{
#endif
		solve();
#ifdef _DEBUG
		cout << "-------" << endl;
	}
#endif
#ifdef _DEBUG
	system("pause");
#endif
	return 0;
}

#define int ll

// bellman ford algorithm O(EV)
// G: adjacency list style Graph
//   G[node][pair<T, int>]: edges(cost, dst_node) start from node.
// start: start node
// 
// note: if graph G has a negative cycle, return empty vector.
//
// usage: auto dist = bellman_ford(G, start);
//template<class T>
//vector<T> bellman_ford(const vector<vector<pair<T, int>>>& G, int start, vector<bool>& is_negative_pass) {
//	vector<T> dists(G.size(), inf);
//	dists[start] = 0;
//	vector<int> prev(G.size(), -1);
//
//	REP(_, G.size() - 1) {
//		REP(node, G.size()) {
//			for (const auto &edge : G[node]) {
//				int nxt_node = edge.second;
//				int next_dist = dists[node] + edge.first;
//				if (dists[nxt_node] > next_dist) {
//					dists[nxt_node] = next_dist;
//					prev[nxt_node] = node;
//				}
//			}
//		}
//	}
//
//	REP(node, G.size()) {
//		for (const auto &edge : G[node]) {
//			int from = node;
//			int to = edge.second;
//			int cost = edge.first;
//			if (dists[to] > dists[from] + cost) {
//				is_negative_pass[to] = true;
//			}
//			if (is_negative_pass[from]) {
//				is_negative_pass[to] = true;
//			}
//		}
//	}
//	return dists;
//}

class edge {
public:
    edge(int to, long long cost);
    int get_to() const;
    long long get_cost() const;
private:
    int to;
    long long cost;
};

edge::edge(int to, long long cost) : to(to), cost(cost) {}

int edge::get_to() const { return to; }

long long edge::get_cost() const { return cost; }


class bellman_ford {
private:
    //unordered_mapを使って隣接グラフを構築
    //first:接続元、second:辺のコストと接続先
    std::unordered_map<int, std::vector<edge>> adj_list;
    int node_num;
    int start_point;
    std::vector<int> pred;//経路（遷移元）を保持
    std::vector<long long> costs;//距離を保持
    bool is_negative_graph;//グラフ内に負のサイクルをもつか否か
    std::vector<bool> is_negative_pass;//経路上に負のサイクルを持つか否か

public:
    bellman_ford(const int node_num, const std::unordered_map<int, std::vector<edge>>& adj_list);
    void calc_min_cost(int start);
    long long get_cost(int end) const;
    bool get_is_negative_graph() const;
    std::vector<int> get_min_path(int end) const;
};

bellman_ford::bellman_ford(const int node_num,
    const std::unordered_map<int, std::vector<edge>>& adj_list) :
    adj_list(adj_list),
    start_point(0),
    node_num(node_num),
    pred(node_num + 1, INT_MAX),
    costs(node_num + 1, LLONG_MAX),
    is_negative_graph(false),
    is_negative_pass(node_num + 1, false)
{}

void bellman_ford::calc_min_cost(int start) {
    this->start_point = start;
    this->pred = std::vector<int>(node_num + 1, INT_MAX);
    this->costs = std::vector<long long>(node_num + 1, LLONG_MAX);
    this->is_negative_pass = std::vector<bool>(node_num + 1, false);

    pred[start] = -1;
    costs[start] = 0;
    for (int i = 0; i < 2 * node_num; i++) {
        for (auto &node : adj_list) {
            if (costs[node.first] == LLONG_MAX) continue;
            for (auto &adj : adj_list[node.first]) {
                int adj_node = adj.get_to();
                long long adj_cost = adj.get_cost() + costs[node.first];
                if (adj_cost < costs[adj_node]) {//計算された隣接頂点のコストが現在のコストより小さいなら
                    costs[adj_node] = adj_cost;//隣接頂点のコストを更新
                    pred[adj_node] = node.first;//隣接頂点の遷移元を更新
                    if (i >= node_num - 1) {
                        //頂点数回以上繰り返しても、
                        //まだ更新が発生するなら、その頂点への経路には負のサイクルあり
                        is_negative_pass[adj_node] = true;
                        is_negative_graph = true;
                    }
                }
                if (is_negative_pass[node.first] == true) {//負のサイクル情報伝搬
                                                           //経路に負のサイクルを含む頂点に連結されているなら、
                                                           //その頂点への経路も負のサイクルを含む
                    is_negative_pass[adj_node] = true;
                }
            }
        }
    }
}

bool bellman_ford::get_is_negative_graph() const {
    return is_negative_graph;
}

long long bellman_ford::get_cost(int end) const {
    if (is_negative_pass[end] == false)
        return costs[end];
    else
        return LLONG_MIN;
}

std::vector<int> bellman_ford::get_min_path(int end) const {
    int node = end;
    std::vector<int> vec;
    vec.push_back(node);
    //終点から始点までの経路をたどる
    while (1) {
        //負のサイクルを含む頂点or
        //始点から辿れない頂点or
        //始点であれば終了
        if (is_negative_pass[node] == true ||
            pred[node] >= INT_MAX || pred[node] == -1) break;
        node = pred[node];
        vec.push_back(node);
    }
    std::reverse(vec.begin(), vec.end());
    return vec;
}

void solve() {
	int N, M, P; cin >> N >> M >> P;
	std::unordered_map<int, vector<edge>> G;
	REP(i, M) {
		int A, B, C; cin >> A >> B >> C;
		--A, --B;
		C = (C - P);
		G[A].push_back(edge(B, -C));
	}
	bellman_ford bf(N, G);
	bf.calc_min_cost(0);
	int res = bf.get_cost(N - 1);
	if (res == LLONG_MIN) {
		cout << -1 << endl;
	}
	else {
		cout << max(-res, 0LL) << endl;
	}
	//vector<bool> flag(G.size() + 1);
	//vector<int> res = bellman_ford(G, 0, flag);
	//if (flag[N-1]) {
	//	cout << -1 << endl;
	//}
	//else {
	//	cout << max(-res[N-1], 0LL) << endl;
	//}
}


Measured memory_bytes: 896