#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16]={0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
template<class T, class S> void BellmanFord(int N, int M, int A[], int B[], T C[], int root, S res[], S unreachable = -1, S minusInf = -2, int step = -1, void *mem = wmem){
  S *arr;
  int KL2GvlyY, i, *inf, j, k, t;
  walloc1d(&inf, N, &mem);
  walloc1d(&arr, N, &mem);
  for(i=0;i<(N);i++){
    inf[i] = 0;
  }
  for(i=0;i<(N);i++){
    res[i] = arr[i] = std::numeric_limits<S>::max();
  }
  res[root] = arr[root] = 0;
  t = step;
  if(t==-1){
    t = N;
  }
  for(KL2GvlyY=0;KL2GvlyY<(t);KL2GvlyY++){
    for(i=0;i<(M);i++){
      if(res[A[i]] != std::numeric_limits<S>::max()){
        chmin(arr[B[i]], res[A[i]] + C[i]);
      }
    }
    for(i=0;i<(N);i++){
      res[i] = arr[i];
    }
  }
  if(step != -1){
    for(i=0;i<(N);i++){
      if(res[i]==std::numeric_limits<S>::max()){
        res[i] = unreachable;
      }
    }
    return;
  }
  for(i=0;i<(M);i++){
    if(res[A[i]] != std::numeric_limits<S>::max()){
      if(arr[B[i]] > res[A[i]] + C[i]){
        inf[B[i]] = 1;
      }
    }
  }
  for(;;){
    int fg=0;
    for(i=0;i<(M);i++){
      if(inf[A[i]] && !inf[B[i]]){
        fg++;
        inf[B[i]] = 1;
      }
    }
    if(!fg){
      break;
    }
  }
  for(i=0;i<(N);i++){
    if(res[i]==std::numeric_limits<S>::max()){
      res[i] = unreachable;
    }
  }
  for(i=0;i<(N);i++){
    if(inf[i]==1){
      res[i] = minusInf;
    }
  }
}
char memarr[96000000];
int N;
int M;
int A[5000];
int B[5000];
int C[5000];
int P;
long long dist[2500];
int main(){
  int i;
  long long res;
  wmem = memarr;
  rd(N);
  rd(M);
  rd(P);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<(M);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);A[Lj4PdHRW] += (-1);
      rd(B[Lj4PdHRW]);B[Lj4PdHRW] += (-1);
      rd(C[Lj4PdHRW]);
    }
  }
  for(i=0;i<(M);i++){
    C[i] = P - C[i];
  }
  BellmanFord(N, M, A, B, C, 0, dist, 0LL, -4611686016279904256LL);
  res = dist[N-1];
  if(res==-4611686016279904256LL){
    res =-1;
  }
  else if(res>0){
    res =0;
  }
  else{
    res =-res;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190818-1 [beta]

// --- original code ---
// int N, M, A[5000], B[5000], C[5000], P;
// ll dist[2500];
// {
//   ll res;
// 
//   rd(N,M,P,(A--,B--,C)(M));
//   rep(i,M) C[i] = P - C[i];
//   BellmanFord(N, M, A, B, C, 0, dist, 0LL, -ll_inf);
// 
//   res = dist[N-1];
//   res = if[res==-ll_inf, -1, res>0, 0, -res];
// 
//   wt(res);
// }


Measured memory_bytes: 512