#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;

signed main() {
  int n,m,p;cin>>n>>m>>p;
  pair<pair<int,int>,int> g[5100];int d[2600];
  rep(i,m){
    cin>>g[i].first.first>>g[i].first.second>>g[i].second;
    g[i].second -= p;g[i].second *= -1;
  }
  rep(i,2600)d[i] = INF;
  d[1] = 0;
  int dd;
  rep(i,2*n){
    bool updated = false;
    rep(j,m){
      pair<int,int> e = g[j].first;int cost = g[j].second;
      if(d[e.first] != INF && d[e.second] > d[e.first]+cost){
        if(i < n-1)d[e.second] = d[e.first]+cost;
        else d[e.second] = -922337203685;
        updated = true;
      }
    }
    if(i < n-1){
      dd = d[n];
    }
    if(!updated)break;
  }
  if(dd == d[n])cout << max((ll)0,d[n]*-1) << endl;
  else cout << -1 << endl;
}
