// 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.127026731507694x):
#include <bits/stdc++.h>



using namespace std;



int n, m, p;

vector<tuple<int, int, int>> edges;

vector<int> graph[2500];

vector<int> reverse_graph[2500];



bool can_reach_rev[2500];

bool can_reach[2500];



int coins[2500];



void dfs(int u) {

  if (can_reach[u]) {

    return;

  }

  can_reach[u] = true;

  for (int v : graph[u]) {

    dfs(v);

  }

}



void reverse_dfs(int u) {

  if (can_reach_rev[u]) {

    return;

  }

  can_reach_rev[u] = true;

  for (int v : reverse_graph[u]) {

    reverse_dfs(v);

  }

}



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(0);

  cin >> n >> m >> p;



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

    coins[i] = INT_MIN/2;

  }



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

    int a, b, c;

    cin >> a >> b >> c;

    c -= p;

    a -= 1;

    b -= 1;

    graph[a].emplace_back(b);

    reverse_graph[b].emplace_back(a);

    edges.emplace_back(a, b, c);

  }

  dfs(0);

  reverse_dfs(n - 1);



  coins[0] = 0;

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

    for (auto t : edges) {

      int u, v, c;

      tie(u, v, c) = t;

      if (can_reach[u] && can_reach_rev[v]) {

        if (coins[u] + c > coins[v]) {

          coins[v] = coins[u] + c;

        }

      }

    }

  }

  for (auto t : edges) {

    int u, v, c;

    tie(u, v, c) = t;

    if (can_reach[u] && can_reach_rev[v]) {

      if (coins[u] + c > coins[v]) {

        printf("-1\n");

        return 0;

      }

    }

  }

  printf("%d\n", max(coins[n - 1], 0));

}