#include <bits/stdc++.h>

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) os << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;


ll N,M,P;
Edges< ll > es;
vector<vector<int>> toList;
vector<vector<int>> rev_toList;

void input(){
  #ifdef __LOCAL
      fs::path p = __FILE__;
      fs::path input,output;
      input = output = p.parent_path();
      input += string("/input/") + string(p.stem()) + string(".txt");
      output += string("/output/") + string(p.stem()) + string(".txt");
      freopen(input.c_str(), "r", stdin);
      freopen(output.c_str(), "w", stdout);
  #endif

  fast_io();
  cin >> N >> M >> P;
  toList.assign(N,vector<int>());
  rev_toList.assign(N,vector<int>());
  for (int i = 0; i < M; i++)
  {
    int a,b;
    ll c;
    cin >> a >> b >> c;
    a--,b--;
    c-=P;
    c *= -1;
    es.emplace_back(a,b,c);
    toList[a].push_back(b);
    rev_toList[b].push_back(a);
  }
}

bool neg[2510];
bool seen[2510],rseen[2510];

template< typename T >
vector< T > bellman_ford(Edges< T > &edges, ll V, ll s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(V, INF);
  dist[s] = 0;
  for(int i = 0; i < V - 1; i++) {
    for(auto &e : edges) {
      if(dist[e.src] == INF) continue;
      dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
    }
  }
  // すべての辺について閉路を検出するのではなくて、
  // 0〜Nの間に閉路があるか検出する。
  // set<int> path = dfs(0);
  // auto ispath=[&](edge< T > e){
  //   auto itr = path.find(e.to);
  //   return (itr!=path.end());
  // };

  for(edge< T > &e : edges) {
    // if(!ispath(e)) continue;
    if(dist[e.src] == INF) continue;
    if(dist[e.src] + e.cost < dist[e.to]) neg[e.src]=true; //return vector< T >(); 負の閉路検出。
  }
  return dist;
}

void dfs(int s){
  seen[s]=true;
  for(auto v:toList[s]) if(!seen[v]) dfs(v);
}

bool dfsr(int s){
  bool ret=seen[s]&&neg[s];
  rseen[s]=true;
  for(auto v:rev_toList[s]) if(!rseen[v]) ret|=dfsr(v);
  return ret;
}

int solve(){
  // ベルマンフォード、ついでに閉路の起点になってるノードの検出
  auto ans = bellman_ford(es,N,0LL);
  dfs(0);
  if(dfsr(N-1)) {cout << -1 << endl;}
  else {cout << max(-ans[N-1],0LL) << endl;}
  return 0;
}

// ダイクストラはダメ
// ベルマンフォードで求める。
int main()
{
  input();
  solve();
  return 0;
}


Measured memory_bytes: 768