#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

int n;
const int N = 2501;
vector<ll> d(N, INF);
using pil = pair<int, ll>;
vector<vector<pil> > G(N);
int flg;

void bell(int s) {
  d[s] = 0;

  int cnt = 0;
  while (1) {
    int update = 0;
    rep(v, n) {
      if (d[v] == INF) continue;
      for (pil p : G[v]) {
        int nv = p.F;
        ll cost = p.S;

        if (chmin(d[nv], d[v] + cost)) {
          update = 1;
        }
      }
    }
    if (update == 0) break;
    cnt++;
    if (cnt == 2 * n) {
      flg = 1;
      return;
    }
  }
}

vector<int> reached(N);
void dfs(int v) {
  for (pil p : G[v]) {
    int nv = p.F;
    if (reached[nv]) continue;
    reached[nv] = 1;
    dfs(nv);
  }
}

void solve() {
  int m, p;
  cin >> n >> m >> p;
  d.resize(n);
  vector<tuple<int, int, int> > v(m);
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    G[b].eb(a, 1);
    v[i] = make_tuple(a, b, c);
  }
  // まずは, ゴールにいけないとこ潰す
  reached.resize(n);
  dfs(n - 1);
  // cout << reached << endl;
  reached[n - 1] = 1; // debuged
  rep(i, n) G[i].clear(); // debuged, G.clear(); error

  rep(i, m) {
    int a, b, c;
    tie(a, b, c) = v[i];
    if (reached[a] == 0 || reached[b] == 0) continue;
    G[a].eb(b, p - c);
  }
  // rep(i, n) { for (pil p : G[i]) { int j = p.F; cout << j << " "; } cout << endl; }
  d[0] = 0;
  bell(0);
  // cout << d << endl;
  if (flg) { cout << -1 << endl; return; }
  // cout << -*min_element(all(d)) << endl;
  cout << max(0LL, -d[n - 1]) << endl; // debuged
}


Measured memory_bytes: 640