//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ld long double
#define pi pair<int,int>
#define pd pair<ld,ld>
#define ft first
#define sd second
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define FOR(i,a,b) for(int i=(a); i<=(b);i++)
#define F(i,a,b) FOR(i,(a),(b)-1)
#define REV(i,a,b) for(int i=(a); i>=(b);i--)
#define VI vector<int>
#define VPI vector<pi>
#define VPD vector<pd>
#define PI 3.14159265
#define all(x) (x).begin(), (x).end()
#define sz(a) (int)((a).size())
#define int long long

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
	while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
mt19937 r(chrono::steady_clock::now().time_since_epoch().count());
int rand_range(int a, int b)
{
	assert(a<=b);
	return a+r()%(b-a+1);
}
const long long K = 1000;
const long long KK = K*K;
const long long MIL = KK*K;
const long long INF = MIL*MIL;
const long long MOD = MIL+7;
const long long N = 3e3 + 10, M=10;
VI G[N];
VI var[N];
int odl[N];

bool zle[N];

void Dijkstra(VI *_graph, VI *_value, int * _distance, int _start)
{
	static int _odl[N];
	static int _ile_razy[N];
	struct _porset{
		bool operator()(int _a, int _b){
			if(_odl[_a] == _odl[_b])
				return _a < _b;
			return _odl[_a] < _odl[_b];
		}
	};
	set<int, _porset> dijkstraSet;
	memset(_odl, 0, sizeof(_odl));
	for(int _i = 0; _i < N; _i++)
		_odl[_i] = LLONG_MAX;
	_odl[_start] = 0;
	dijkstraSet.clear();
	dijkstraSet.insert(_start);
	while(!dijkstraSet.empty()){
		int _x = *dijkstraSet.begin();
		dijkstraSet.erase(_x);
		_ile_razy[_x]++;
        if(_ile_razy[_x] > N) {
            zle[_x] = true;
            continue;
        }
		for(int _i = 0; _i < _graph[_x].size(); _i++){
			int _a = _graph[_x][_i];
			if(_odl[_x] + _value[_x][_i] < _odl[_a]){
				if(_odl[_a] < LLONG_MAX)
					dijkstraSet.erase(_a);
				_odl[_a] = _odl[_x] + _value[_x][_i];
				dijkstraSet.insert(_a);
			}
		}
	}
	memcpy(_distance, _odl, sizeof(_odl));
}


bool vis[N];
void dfs(int x) {
    vis[x] = true;
    for(int i : G[x]) {
        zle[i] |= zle[x];
        if(!vis[i])
            dfs(i);
    }
}

void solve(){
    int n, m, p;
    cin>>n>>m>>p;
    F(i,0,m) {
        int a, b, c;
        cin>>a>>b>>c;
        G[a].eb(b);
        var[a].eb(-c + p);
        debug(a, b, -c + p);
    }
    Dijkstra(G, var, odl, 1);

    dfs(1);
    //FOR(i, 1, n)
    //    debug(i, zle[i], odl[i]);
    if(zle[n] || odl[n] == LLONG_MAX)
        cout<<"-1\n";
    else
        cout<<max(-odl[n], 0LL)<<"\n";
}

int32_t main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	//ios_base::sync_with_stdio(0);
	//cin.tie(0);
	//cout.tie(0);
	cerr.tie(0);
	cout<<setprecision(9)<<fixed;
	cerr<<setprecision(6)<<fixed;
	int test = 1, f;
    //cin>>test;
	F(_test, 0, test){
        //cout<<"Case #"<<_test + 1<<": ";
		solve();
//		if(_test == 1)
//            return 0;
	}
}
/*
3 3 10
1 2 11
2 1 10
2 3 20
*/


Measured memory_bytes: 768