#include<bits/stdc++.h>
using namespace std;

struct edge{
  int64_t from;
  int64_t to;
  int64_t cost;
};

int main(){
  int64_t N, M, P;
  cin >> N >> M >> P;
  vector<edge> G(M);
  for(int i=0; i<M; i++){
    int64_t a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    c -= P;
    edge add;
    add.from = a;
    add.to = b;
    add.cost = c*-1;
    G.at(i) = add;
  }
  int64_t INF = 1e18;
  vector<int64_t> dist(N,INF);
  dist.at(0) = 0;
  vector<bool> inf(N,false);
  for(int i=0; i<2*N; i++){
    for(int j=0; j<M; j++){
      edge e = G.at(j);
      if(dist.at(e.from) != INF && dist.at(e.to) > dist.at(e.from) + e.cost){
        dist.at(e.to) = dist.at(e.from) + e.cost;
        if(i >= N-1){
          dist.at(e.to) = -INF;
        }
      }
    }
  }
  if(dist.at(N-1) == -INF){
    cout << -1 << endl;
  }
  else{
    cout << max((int64_t)0,dist.at(N-1)*-1) << endl;
  }
}

