#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i > 0; i--)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
void solve() {
  ll N, M, P;
  cin >> N >> M >> P;
  vector<ll> A(M), B(M), C(M);
  REP(i, M) {
    cin >> A[i] >> B[i] >> C[i];
  }
  vector<ll> d(N, INF);
  d[0] = 0;
  REP(i, 2 * N) {
    REP(j, M) {
      ll from = A[j] - 1, to = B[j] - 1, cost = P - C[j];
      if(d[from] < INF && d[to] > d[from] + cost) {
        if(i < N - 1) {
          d[to] = d[from] + cost;
        } else {
          d[to] = -INF;
        }
      }
    }
  }
  cout << (d[N-1] <= -INF ? -1 : max(0ll, -d[N-1])) << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
