#include <stdio.h>
#include <stdlib.h>
#include <utility>
#include <vector>

#define MAX_N (2500L)
#define MAX_M (5000L)
#define INF (1000000000000000000L)

using namespace std;

//たどり着けないときはLLINF、負の閉路を持つときは-LLINFを返す。
struct Bellman_Ford {
  long N;
  long *d;
  long *pre;
  bool *negative;
  vector<pair<pair<long, long>, long>> edges;
  Bellman_Ford(long N) : N(N) {
    d = new long[N];
    pre = new long[N];
    negative = new bool[N];
    for (long i = 0; i < N; i++) {
      d[i] = INF;
      pre[i] = -1;
      negative[i] = false;
    }
  }
  void push_nondir(long a, long b, long c) {
    edges.push_back(make_pair(make_pair(a, b), c));
    edges.push_back(make_pair(make_pair(b, a), c));
  }
  void push_dir(long a, long b, long c) {
    edges.push_back(make_pair(make_pair(a, b), c));
  }
  long solve(long start, long end) {
    d[start] = 0;
    for (long i = 0; i < N - 1; i++) {
      for (long j = 0; j < edges.size(); j++) {
        long from = edges[j].first.first;
        long to = edges[j].first.second;
        long cost = edges[j].second;
        if (d[to] > d[from] + cost) {
          d[to] = d[from] + cost;
          pre[to] = from;
        }
      }
    }
    // startからendにいく回路の中に負の重みの閉路がある？
    for (long i = 0; i < N; i++) {
      for (long j = 0; j < edges.size(); j++) {
        long from = edges[j].first.first;
        long to = edges[j].first.second;
        long cost = edges[j].second;
        if (d[to] > d[from] + cost) {
          d[to] = d[from] + cost;
          negative[to] = true;
        }
        if (negative[from]) negative[to] = true;
      }
    }
    if (negative[end])
      return -INF;
    else
      return d[end];
  }
  bool anywhere_negativeC() {  // do after solve()
    for (long i = 0; i < edges.size(); i++) {
      long from = edges[i].first.first;
      long to = edges[i].first.second;
      long cost = edges[i].second;
      if (d[to] > d[from] + cost) return true;
    }
    return false;
  }
  void free_BF() {
    delete[] d;
    delete[] pre;
    delete[] negative;
  }
};

long dfs(const vector<vector<long>> &adj_lists, vector<long> &vs, long cur) {
  for (long nxt : adj_lists[cur]) {
    if (!vs[nxt]) {
      vs[nxt] = 1;
      dfs(adj_lists, vs, nxt);
    }
  }
}

int main(int argc, char *argv[]) {
  // read inputs
  long N, M, P, as[MAX_M], bs[MAX_M], cs[MAX_M];
  scanf("%ld %ld %ld", &N, &M, &P);
  for (long i = 0; i < M; i++) {
    scanf("%ld %ld %ld", &as[i], &bs[i], &cs[i]);
    as[i]--;  // NOTE : modified input
    bs[i]--;  // NOTE : modified input
  }

  // create graphs
  vector<vector<long>> adj_lists(N, vector<long>()),
      rev_adj_lists(N, vector<long>());
  for (long i = 0; i < M; i++) {
    const long a = as[i], b = bs[i];
    adj_lists[a].push_back(b);
    rev_adj_lists[b].push_back(a);
  }

  // only consider nodes that can be visited from node 0 and
  // can visit node N - 1 after.
  vector<long> vs_0(N, 0), vs_nm1(N, 0);
  vs_0[0] = 1;
  dfs(adj_lists, vs_0, 0);
  vs_nm1[N - 1] = 1;
  dfs(rev_adj_lists, vs_nm1, N - 1);
  // for (long i = 0; i < N; i++) {
  //   printf("i = %ld, v0 = %ld, vnm1 = %ld\n", i, vs_0[i], vs_nm1[i]);
  // }

  // create graph
  Bellman_Ford bf(N);
  for (long i = 0; i < M; i++) {
    const long a = as[i], b = bs[i];
    if (vs_0[a] && vs_0[b] && vs_nm1[a] && vs_nm1[b]) {
      bf.push_dir(bs[i], as[i], -(cs[i] - P));
      // printf("%ld -> %ld: %ld\n", bs[i], as[i], -(cs[i] - P));
    }
  }
  long ans = bf.solve(N - 1, 0);
  if (ans == -INF) {
    printf("-1\n");
  } else {
    printf("%ld\n", max(-ans, 0L));
  }

  return 0;
}


Measured memory_bytes: 1088