// Slower C++ solution:
#include<bits/stdc++.h>



using namespace std;

#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)

#define REP(i,a,b) REPP(i,a,b,1)

#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)

#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) REP(i,0,(int)a-1)

#define FORD(i,a) REV(i,(int)a-1,0)

#define PB push_back

#define POB pop_back

#define MP make_pair

#define FI first

#define SE second

typedef long long ll;

typedef unsigned long long ull;

typedef pair < int , int > pii;

typedef vector < int > vi;

typedef vector < pii > vii;

typedef vector < ll > vl;



const double EPS = 1e-9;

const double PI = acos(-1);

const ll INF = 1e15;

const ll MOD = 1e9 + 7;



ll addMod(ll a, ll b){

	return (a+b) % MOD;

}



ll mulMod(ll a, ll b){

	return (a*b) % MOD;

}



ll fast(ll a, ll b){

	if(b == 0) return 1;

	ll tmp = fast(a,b/2);

	tmp = mulMod(tmp, tmp);

	if(b & 1) tmp = mulMod(tmp, a);

	return tmp;

}



/////////////////////////////////////////////////////////



const int N = 5000;



ll n,m,p;

ll dist[N + 5];

ll u[N + 5], v[N + 5], w[N + 5];

vi G[N + 5], G2[N + 5];

bool vis[N + 5][3];



void dfs(int u){

	vis[u][1] = true;

	for(auto v : G[u]){

		if(!vis[v][1]){

			dfs(v);

		}

	}

}



void dfs2(int u){

	vis[u][0] = true;

	for(auto v : G2[u]){

		if(!vis[v][0]){

			dfs2(v);

		}

	}

}



ll solve(){

	REP(i,1,n) dist[i] = INF;

	dist[1] = 0;

	FOR(j,n){

		FOR(i,m){

			if(vis[v[i]][0] && vis[u[i]][0] && vis[v[i]][1] && vis[u[i]][1] && dist[v[i]] > dist[u[i]] + w[i]){

				dist[v[i]] = dist[u[i]] + w[i];

				if(j == n-1 && vis[v[i]][0] && vis[v[i]][1]){

					return -1;

				}

			}

		}

	}

	if(dist[n] > 0) dist[n] = 0;

	return -dist[n];

}



int main(){

	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

	memset(vis,0,sizeof vis);

	cin >> n >> m >> p;

	FOR(i,m){

		cin >> u[i] >> v[i] >> w[i], w[i] = p - w[i];

		G[u[i]].PB(v[i]);

		G2[v[i]].PB(u[i]);

	}

	dfs(1); dfs2(n);

	cout << solve() << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1900370489734753x):
#include<bits/stdc++.h>

#define MAXN 2510

using namespace std;



int dist[MAXN];

vector<pair<pair<int, int>, int> > edges;

vector<int> gr_inv[MAXN];



bool reachable[MAXN];

void dfs(int u){

    if(reachable[u])

        return ;

    reachable[u] = true;

    for(auto &p : gr_inv[u]){

        dfs(p);

    }

}

int main(){

    ios::sync_with_stdio(0);

    cin.tie(0);

    int N, M, P;

    cin >> N >> M >> P;

    for(int i = 1; i <= N; i++)

        reachable[i] = false;

    for(int i = 0; i < M; i++){

        int a, b, c;

        cin >> a >> b >> c;

        edges.push_back(make_pair(make_pair(a, b), P-c));

        gr_inv[b].push_back(a);

    }

    dfs(N);

    for(int j = 0; j <= N; j++){

        dist[j] = 2e9;

    }



    dist[1] = 0;



    for (int i = 1; i <= N - 1; i++) { 

        for (int j = 0; j < M; j++) { 

            int u = edges[j].first.first;

            int v = edges[j].first.second; 

            int weight = edges[j].second; 

            if (dist[u] != 2e9 && dist[u] + weight < dist[v]) 

                dist[v] = dist[u] + weight; 

        } 

    } 

  

    bool has_answer = true;

    for (int i = 0; i < M; i++) { 

        int u = edges[i].first.first;

        int v = edges[i].first.second; 

        int weight = edges[i].second; 

        if (dist[u] != 2e9 && dist[u] + weight < dist[v]) { 

            if(reachable[u])

                has_answer = false;

        } 

    } 

    if(!has_answer){

        cout << "-1\n";

    } else {

        cout << max(0, -dist[N]) << "\n";

    }

    return 0;

}