#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 2501

ll n,m,p;

struct Edge {
    ll a, b, cost;
    Edge(ll a,ll b,ll cost) : a(a) , b(b) , cost(cost) {}
};

vector<Edge> edges;
const ll INF = 1e18;

bool neg_cycle;

ll solve()
{
    vector<ll> d(n);
    d[0] = 0;
    For(i,1,n){
    	d[i] = INF;
    }


    ll x;
    for (ll i = 0; i < n+1; ++i) {
        x = -1e18;
        for (Edge e : edges) {
            if (d[e.a] + e.cost < d[e.b]) {
                d[e.b] = d[e.a] + e.cost;
                x = e.b;
            }
        }
    }

    if(x!=-1e18){
    	neg_cycle = 1;
    	return -1;
    }else{
    	return d[n-1];
    }

    // if (x == -1) {
    //     cout << "No negative cycle found.";
    // } else {
    //     for (ll i = 0; i < n; ++i)
    //         x = p[x];

    //     vector<ll> cycle;
    //     for (ll v = x;; v = p[v]) {
    //         cycle.push_back(v);
    //         if (v == x && cycle.size() > 1)
    //             break;
    //     }
    //     reverse(cycle.begin(), cycle.end());

    //     cout << "Negative cycle: ";
    //     for (ll v : cycle)
    //         cout << v << ' ';
    //     cout << endl;
    // }

    // return 0;
}

vector<ll> adj[2][MAX];

set<ll> s[2];

void fill(ll x,ll g){
	bool visited[n];
	memset(visited,0,sizeof(visited));
	visited[x]=1;
	queue<ll> q;
	q.push(x);

	while(q.size()>0){
		ll c = q.front();q.pop();
		s[g].insert(c);
		for(ll x:adj[g][c]) if(!visited[x]){
			visited[x]=1;
			q.push(x);
		}
	}
	return;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	neg_cycle = 0;
	cin>>n>>m>>p;
	vector<Edge> input;
	For(i,0,m){
		ll x,y,c;cin>>x>>y>>c;x--;y--;
		adj[0][x].pb(y);
		adj[1][y].pb(x);
		input.pb(Edge(x,y,p-c));
		// edges.pb(Edge(x,y,p-c));
	}
	fill(0,0);
	fill(n-1,1);

	for(Edge e:input){
		if(s[0].find(e.a)!=s[0].end() && s[1].find(e.b)!=s[1].end()){
			edges.pb(e);
		}
	}

	ll ans = solve();
	if(neg_cycle){
		cout<<-1<<endl;
	}else{
		if(ans>=0){
			cout<<0<<endl;
		}else{
			cout<<abs(ans)<<endl;
		}
	}
































	
}

Measured memory_bytes: 1220