#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;
}
struct graph{
  int N, **edge, *es;
  void setDirectEdge(int N__, int M, int A[], int B[], void **mem = &wmem){
    int i;
    N = N__;
    walloc1d(&es, N, mem);
    walloc1d(&edge, N, mem);
    walloc1d(&edge[0], M, mem);
    for(i=0;i<(N);i++){
      es[i] = 0;
    }
    for(i=0;i<(M);i++){
      es[A[i]]++;
    }
    for(i=0;i<(N);i++){
      walloc1d(&edge[i], es[i], mem);
    }
    for(i=0;i<(N);i++){
      es[i] = 0;
    }
    for(i=0;i<(M);i++){
      edge[A[i]][es[A[i]]++] = B[i];
    }
  }
}
;
template<class T> struct wgraph{
  T **cost;
  graph g;
  int N, **edge, *es;
  void setDirectEdge(int N__, int M, int A[], int B[], T C[], void **mem = &wmem){
    int i;
    N = N__;
    walloc1d(&es, N, mem);
    for(i=0;i<(N);i++){
      es[i] = 0;
    }
    for(i=0;i<(M);i++){
      es[A[i]]++;
    }
    walloc1d(&edge, N, mem);
    for(i=0;i<(N);i++){
      walloc1d(&edge[i], es[i], mem);
    }
    walloc1d(&cost, N, mem);
    for(i=0;i<(N);i++){
      walloc1d(&cost[i], es[i], mem);
    }
    for(i=0;i<(N);i++){
      es[i] = 0;
    }
    for(i=0;i<(M);i++){
      edge[A[i]][es[A[i]]] = B[i];
      cost[A[i]][es[A[i]]++] = C[i];
    }
    g.N = N;
    g.es = es;
    g.edge = edge;
  }
  template<class S> void BellmanFord(int root, S res[], S unreachable = -1, S minusInf = -2, int step = -1, void *mem = wmem){
    S *arr;
    int KL2GvlyY, i, *inf, j, k, *q, qe, qs, t;
    walloc1d(&q, N, &mem);
    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<(N);i++){
        if(res[i] != std::numeric_limits<S>::max()){
          for(j=0;j<(es[i]);j++){
            chmin(arr[edge[i][j]], res[i] + cost[i][j]);
          }
        }
      }
      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<(N);i++){
      if(res[i] != std::numeric_limits<S>::max()){
        for(j=0;j<(es[i]);j++){
          k = edge[i][j];
          if(arr[k] > res[i] + cost[i][j]){
            inf[k] = 1;
          }
        }
      }
    }
    qs = qe = 0;
    for(i=0;i<(N);i++){
      if(inf[i]){
        q[qe++] = i;
      }
    }
    while(qs < qe){
      i = q[qs++];
      for(j=0;j<(es[i]);j++){
        k = edge[i][j];
        if(inf[k]==0){
          inf[k] = 1;
          q[qe++] = k;
        }
      }
    }
    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;
  wgraph<int> g;
  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];
  }
  g.setDirectEdge(N,M,A,B,C);
  g.BellmanFord(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 20190826-1 [beta]

// --- original code ---
// int N, M, A[5000], B[5000], C[5000], P;
// ll dist[2500];
// {
//   ll res;
//   wgraph<int> g;
// 
//   rd(N,M,P,(A--,B--,C)(M));
//   rep(i,M) C[i] = P - C[i];
//   g.setDirectEdge(N,M,A,B,C);
//   g.BellmanFord(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