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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

template <typename CLASS1, typename CLASS2>
bool operator==(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value == hoge2.value;
};

template <typename CLASS1, typename CLASS2>
bool operator<(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value < hoge2.value;
};

template <typename CLASS1, typename CLASS2>
bool operator>(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value > hoge2.value;
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

class Bellman_Ford{
  //Bellman-Ford algorithm 
  //calculation time complexity: O(|V||E|)
  //useful with negative cost
  private:
    struct edge {ll from, to, cost; };
    vector<edge> es;

    ll V, E;
    vector<ll> d;
    vector<ll> prev;

  public:
    Bellman_Ford(ll V, vector<ll> From, vector<ll> To, vector<ll> Cost){
      //num of vertex
      this->V = V;
      d.resize(V, INFLL);
      prev.resize(V, -1);
      E = (ll)From.size();
      if(To.size() != E || Cost.size() != E){
        fprintf(stderr, "Sizes are different, %ld %ld %ld\n", From.size(), To.size(), Cost.size());
        exit(0);
      }
      es.resize(E);
      for(ll i=0; i<E; ++i){
        es[i].from = From[i];
        es[i].to = To[i];
        es[i].cost = Cost[i];
      }
      return;
    };

    ~Bellman_Ford(void){
      return;
    };

    //calculate shortest path from s vertex to others
    void shortest_path(ll s){
      for(ll i=0; i<V; ++i) d[i] = INFLL;
      d[s] = 0;
      while(true){
        bool update = false;
        for(ll i=0; i<E; i++){
          edge e = es[i];
          if(d[e.from] != INFLL && d[e.to]>d[e.from] + e.cost){
            d[e.to] = d[e.from] + e.cost;
            prev[e.to] = e.from;
            update = true;
          }
        }
        if(!update) break;
      }
    };

    ll get_distance(ll vertex){
      return d[vertex];
    };

    //shortest path to vertex t
    vector<ll> get_path(ll t){
      vector<ll> path;
      for(; t!=-1; t=prev[t]){
        path.push_back(t);
      }
      reverse(path.begin(), path.end());
      return path;
    };

    bool find_negative_loop(void){
      for(ll i=0; i<V; ++i) d[i] = 0;

      for(ll i=0; i<V; i++){
        for(ll j=0; j<E; j++){
          edge e = es[j];
          if(d[e.to] > d[e.from] + e.cost){
            d[e.to] = d[e.from] + e.cost;

            if(i == V-1) return true;
          }
        }
      }
      return false;
    };
};

ll N, M, P;
vll A, B, C;
vvpll Graph;
vvpll InvGraph;
unordered_set<ll> touchable1;
unordered_set<ll> touchable2;

void search1(ll pos){
  if(touchable1.find(pos)==touchable1.end()){
    touchable1.emplace(pos);
    REP(i,InvGraph[pos].size()) search1(InvGraph[pos][i].first);
  }
  return;
}

void search2(ll pos){
  if(touchable1.find(pos)==touchable1.end()) return;
  if(touchable2.find(pos)==touchable2.end()){
    touchable2.emplace(pos);
    REP(i,Graph[pos].size()) search2(Graph[pos][i].first);
  }
  return;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  IN(N,M,P);
  A.resize(M);
  B.resize(M);
  C.resize(M);
  Graph.resize(N);
  InvGraph.resize(N);
  REP(i,M){
    IN(A[i], B[i], C[i]);
    A[i]--;
    B[i]--;
    C[i]-=P;
    pair<ll, ll> tmp1(B[i], C[i]);
    pair<ll, ll> tmp2(A[i], C[i]);
    InvGraph[B[i]].pb(tmp2);
    Graph[A[i]].pb(tmp1);
  }

  search1(N-1);
  search2(0);

  if(touchable2.find(0)==touchable2.end()){
    OUT(-1);
    return 0;
  }

  vll From;
  vll To;
  vll Cost;

  REP(i,M){
    if(touchable2.find(A[i])==touchable2.end()) continue;
    if(touchable2.find(B[i])==touchable2.end()) continue;
    From.pb(A[i]);
    To.pb(B[i]);
    Cost.pb(-C[i]);
    //printf("%lld %lld %lld\n", A[i], B[i], C[i]);
  }

  Bellman_Ford BF(N, From, To, Cost);
  if(BF.find_negative_loop()){
    OUT(-1);
    return 0;
  }
  BF.shortest_path(0);

  /*
  for(int i=0; i<N; ++i){
    printf("%lld %lld\n", i, -BF.get_distance(i));
  }
  */

  ll ans = -BF.get_distance(N-1);

  if(ans==INFLL) OUT(-1);
  else OUT(max(ans, (ll)0));


  return 0;
}

Measured memory_bytes: 1408