// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
// problem: longest distance from 0 to V-1, checking for positive cycle only on this path

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll INF = 1 << 30;



struct Tadj {

	int id, w;

};

vector<vector<Tadj>> adjList;

int V;



vector<ll> ld;



vector<bool> visited;

void dfs(int u) {

   if (visited[u]) return;

   visited[u] = 1;

   for (Tadj v : adjList[u])

      dfs(v.id);

}



/* O(V*E) - retorna true se há um ciclo positivo entre 0 e V-1 */

bool belmman_ford(int s) {

   ld.assign(V, -INF); ld[s] = 0;



   ll first0, first1;

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

      // para cada aresta u --v.w--> v.id

      for (int u = 0; u < V; u++)

         for (Tadj v : adjList[u]) {

            if (ld[u] + v.w > ld[v.id] && ld[u] > -INF) {

               ld[v.id] = ld[u] + v.w;



               // se ainda conseguiu relaxar depois das V-1 vezes anteriores

               if (i == V-1) {

                  visited.assign(V, 0);

                  dfs(v.id);

                  if (visited[0] || visited[V-1]) return true;

               }

            }

         }

   }



   return false;

}



int main() {

   int E, P; cin >> V >> E >> P;

   adjList.assign(V, vector<Tadj>());

   while (E--) {

      int u, v, w; cin >> u >> v >> w; u--; v--; w -= P;

      adjList[u].push_back({v, w});

   }



   cout << (belmman_ford(0)? -1 : max(ld[V-1], 0ll)) << endl;

}

// Fastest known solution for this problem: