#include <bits/stdc++.h>
const int MAX_N = 2500;
const int MAX_M = 5000;
struct edge {
  int from, to, cost;
};
edge es[MAX_M];
bool jb[MAX_N], jf[MAX_N];
int ben[MAX_N];
int n, m, p;
int main() {
  scanf("%d %d %d", &n, &m, &p);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    es[i].from = a - 1;
    es[i].to = b - 1;
    es[i].cost = c - p;
  }
  jb[n - 1] = true;
  jf[0] = true;
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < m; j++) {
      if (jb[es[j].to]) jb[es[j].from] = true;
      if (jf[es[j].from]) jf[es[j].to] = true;
    }
  }
  bool update;
  for (int i = 1; i < n; i++) ben[i] = -1e9;
  for (int i = 0; i < n; i++) {
    update = false;
    for (int j = 0; j < m; j++) {
      if (ben[es[j].to] < ben[es[j].from] + es[j].cost && jb[es[j].to] &&
          jf[es[j].from]) {
        ben[es[j].to] = ben[es[j].from] + es[j].cost;
        update = true;
      }
    }
  }
  if (update) {
    printf("-1\n");
    return 0;
  }
  printf("%d\n", std::max(ben[n - 1], 0));
  return 0;
}
