// Slower C++ solution:
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;



const int INF = 1001001001;



vector<int> to[2505];

vector<int> rto[2505];

bool reachableFrom1[2505];

bool reachableToN[2505];

bool ok[2505];



void dfs(int v) {

  if (reachableFrom1[v]) return;

  reachableFrom1[v] = true;

  for (int u : to[v]) {

    dfs(u);

  }

}

void rdfs(int v) {

  if (reachableToN[v]) return;

  reachableToN[v] = true;

  for (int u : rto[v]) {

    rdfs(u);

  }

}



int main() {

  int n, m, p;

  cin >> n >> m >> p;

  vector<tuple<int,int,int>> edges;

  rep(i,m) {

    int a, b, c;

    cin >> a >> b >> c;

    --a; --b;

    c -= p;

    c = -c;

    edges.emplace_back(a,b,c);

    to[a].push_back(b);

    rto[b].push_back(a);

  }

  dfs(0);

  rdfs(n-1);

  rep(i,n) ok[i] = reachableFrom1[i]&reachableToN[i];

  { // bellman-ford

    vector<int> d(n,INF);

    d[0] = 0;

    bool upd = true;

    int step = 0;

    while (upd) {

      upd = false;

      rep(i,m) {

        int a, b, c;

        tie(a,b,c) = edges[i];

        if (!ok[a]) continue;

        if (!ok[b]) continue;

        int newD = d[a]+c;

        if (newD < d[b]) {

          upd = true;

          d[b] = newD;

        }

      }

      step++;

      if (step > n) {

        puts("-1");

        return 0;

      }

    }

    int ans = -d[n-1];

    ans = max(ans, 0);

    cout << ans << endl;

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.123928571362379x):
#include<bits/stdc++.h>

using namespace std;

using ll = long long;

using ld = long double;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)

#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)

#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)

#define ALL(x) x.begin(),x.end()

#define fs first

#define sd second

#define couts(x) cout << (x) << (" ")

#define coutn(x) cout << (x) << ("\n")

#define endl "\n"



template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &vec){ for (auto &v : vec) is >> v; return is; }

template<typename T1, typename T2> std::istream &operator>>(std::istream &is, std::pair<T1,T2> &p){is >> p.first >> p.second; return is; }

template<typename T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }

template<typename T> std::ostream &operator<<(std::ostream &os, const std::deque<T> &vec){ os << "deque["; for (auto v : vec) os << v << ","; os << "]"; return os; }

template<typename T> std::ostream &operator<<(std::ostream &os, const std::set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }

template<typename T> std::ostream &operator<<(std::ostream &os, const std::unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }

template<typename T> std::ostream &operator<<(std::ostream &os, const std::multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }

template<typename T> std::ostream &operator<<(std::ostream &os, const std::unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }

template<typename T1, typename T2> std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }

template<typename TK, typename TV> std::ostream &operator<<(std::ostream &os, const std::map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }

template<typename TK, typename TV> std::ostream &operator<<(std::ostream &os, const std::unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }



template<class T> using V = vector<T>;

template<class T> using V2 = V<V<T>>;

template<class T> using V3 = V<V2<T>>;

template<class T> using V4 = V<V3<T>>;

using P = pair<int,ll>;



struct edge {ll from, to, cost;};

V<bool> reachable_from1, reachable_fromn, included_path;

V2<P> g_pos, g_neg;

bool N_EQ_INF = false;



void dfs_pos(int s){

  if(reachable_from1[s]) return;

  reachable_from1[s] = true;

  for(auto x: g_pos[s]){

    dfs_pos(x.fs);

  }

  return;

}



void dfs_neg(int s){

  if(reachable_fromn[s]) return;

  reachable_fromn[s] = true;

  for(auto x: g_neg[s]){

    dfs_neg(x.fs);

  }

  return;

}



void bellmanford(V<edge> &g, V<ll> &dist, int Vn, int En, int s, bool bl = false){

  ll inf_ = 1LL<<40;

  if(bl){

  	for(int i=0; i<Vn; ++i) dist[i] = inf_;

  	dist[s] = 0;

  }

  for(int i=0; i<Vn; ++i){

    for(int j=0; j<En; ++j){

      edge e = g[j];

      if(dist[e.to]>dist[e.from]+e.cost){

        dist[e.to] = dist[e.from] + e.cost;

        //if(i==Vn-1) return;

      }

    }

  }

  for(auto e: g){

    int u = (int)e.from, v = (int)e.to; ll w = e.cost;

    if(!included_path[u]) continue;

    if(dist[u]+w<dist[v]) N_EQ_INF = true;

  }

}



void solve(){

  int n, m, p; cin >> n >> m >> p;

  V<edge> g(m); 

  g_pos = V2<P>(n);

  g_neg = V2<P>(n);

  reachable_from1 = V<bool>(n,false);

  reachable_fromn = V<bool>(n,false);

  included_path = V<bool>(n,false);

  FOR(i,0,m){

    int a, b, c;

    cin >> a >> b >> c;

    --a; --b;

    c -= p;

    c *= -1;

    g[i].from = a;

    g[i].to = b;

    g[i].cost = c;

    g_pos[a].emplace_back(b, c);

    g_neg[b].emplace_back(a, c);

  }

  dfs_pos(0);

  dfs_neg(n-1);

  FOR(i,0,n) included_path[i] = reachable_from1[i] && reachable_fromn[i];

  V<ll> dist(n,(1LL<<40));dist[0] = 0;

  bellmanford(g,dist,n,m,0,true);

  ll ans = max(-dist[n-1],(ll)0);

  if(N_EQ_INF) coutn(-1);

  else coutn(ans);

}



int main(){

  solve();

  return 0;

}