#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

const ll inf = 1e18;

struct edge {
  int u, v, wt;
};

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int n, m, p;
  cin >> n >> m >> p;
  vector < edge > edges(m);
  for (int i = 0; i < m; i++) {
    cin >> edges[i].u >> edges[i].v >> edges[i].wt;
    edges[i].wt = p - edges[i].wt;
  }

  vector < ll > d(n + 1, LLONG_MAX);
  d[1] = 0;
  for (int i = 0; i < 2 * n; i++) {
    for (edge e : edges) {
      int u = e.u, v = e.v, wt = e.wt;
      if (d[u] != LLONG_MAX && d[v] > d[u] + (ll)wt) {
        d[v] = max(-inf, d[u] + wt);
        if (i > n - 1) d[v] = -inf;
      }
    }
  }

  if (d[n] == -inf) {
    // graph has -ve cycles from 1.
    cout << -1 << '\n';
  } else {
    cout << max( -d[n], (ll)0) << '\n';
  }
}
