#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;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-9
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 2505
#define MAXM 5005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

const ld PI = (ld)4*atanl(1);

mt19937 g1(chrono::steady_clock::now().time_since_epoch().count());

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int N,M,P;
ll dis[MAXN];
bool good[MAXN],vis[MAXN];
pair<pii,int> edges[MAXM];
vector<pii> adj[MAXN];

void init(int st){
    memset(vis,false,sizeof vis);
    queue<int> q;
    q.push(st);
    vis[st] = true;
    while(q.size()){
        int node = q.front(); q.pop();
        for(pii check:adj[node]){
            if(vis[check.first]) continue;
            vis[check.first] = true;
            q.push(check.first);
        }
    }
    good[st] = vis[N];
}

int main(){
//    freopen("data.in","r",stdin);
    fastio; cin >> N >> M >> P;
    for(int i=1; i<=M; i++){
        int a,b,c; cin >> a >> b >> c;
        edges[i] = mp(mp(a,b),P-c);
        adj[a].pb(mp(b,c-P));
    }
    for(int i=1; i<=N; i++) init(i);
    init(1);
    for(int i=1; i<=N; i++)
        good[i]&=vis[i];
    int x = -1;
    for(int i=0; i<N; i++){
        x = -1;
        for(int k=1; k<=M; k++){
            if(!good[edges[k].first.first] || !good[edges[k].first.second]) continue;
            if(dis[edges[k].first.first]+edges[k].second < dis[edges[k].first.second]){
                dis[edges[k].first.second] = dis[edges[k].first.first]+edges[k].second;
                x = edges[k].first.second;
            }
        }
    }
    if(!good[1] || x != -1){
        cout << -1 << endl;
        return 0;
    }
    memset(dis,-0x3f,sizeof dis);
    priority_queue<pair<ll,int>> q;
    q.push(mp(0,1));
    dis[1] = 0;
    while(q.size()){
        ll d = q.top().first; int node = q.top().second; q.pop();
        if(dis[node] > d) continue;
        for(pii check:adj[node]){
            if(good[check.first] && dis[check.first] < dis[node]+check.second){
                dis[check.first] = dis[node]+check.second;
                q.push(mp(dis[check.first],check.first));
            }
        }
    }
    cout << max(0LL,dis[N]) << endl;
}

Measured memory_bytes: 640