#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(void) {}
  Edge(int src, int dst) : src(src), dst(dst) {}
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void edges_to_graph(Graph &graph, const Edges &edges, const int vertices, const bool directed = true) {
  graph.clear(), graph.resize(vertices);
  for (const auto &e : edges) graph[e.src].emplace_back(e);
  if (!directed) for (const auto &e : edges) graph[e.dst].emplace_back(Edge(e.dst, e.src, e.weight));
}

void bfs(Graph &g, const int s, vector<bool> &checked) {
  queue<int> que;
  que.push(s);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    if (checked[v]) continue;
    checked[v] = true;
    for (const auto &e : g[v]) {
      if (checked[e.dst]) continue;
      que.push(e.dst);
    }
  }
}

template <typename T>
bool bellman_ford(const Graph &graph, const int s, vector<T> &dist, vector<bool> &checked) {
  const int   n   = graph.size();
  constexpr T inf = numeric_limits<T>::max();
  dist.assign(n, inf);
  dist[s] = 0;
  for (int x = 0, lim = n - 1; x < lim; ++x) {
    for (int i = 0; i < n; ++i) {
      if (dist[i] == inf) continue;
      for (const auto &e : graph[i]) {
        dist[e.dst] = min(dist[e.dst], dist[i] + e.weight);
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (dist[i] == inf || !checked[i]) continue;
    for (const auto &e : graph[i]) {
      if (!checked[e.dst]) continue;
      if (dist[i] + e.weight < dist[e.dst]) return false;
    }
  }
  return true;
}

Graph graph;
int main(void) {
  int n, m, p;
  cin >> n >> m >> p;
  Edges edges(m), redges(m);
  rep (i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    edges[i]  = {--a, --b, p - c};
    redges[i] = {b, a};
  }
  edges_to_graph(graph, redges, n);
  vector<bool> checked(n), checkedn(n);
  bfs(graph, n - 1, checkedn);
  edges_to_graph(graph, edges, n);
  bfs(graph, 0, checked);
  rep (i, n) checked[i] = checked[i] & checkedn[i];
  vector<int> dist;
  bool ret = bellman_ford(graph, 0, dist, checked);
  cout << (ret ? max(0, -dist[n - 1]) : -1) << endl;
  return 0;
}

Measured memory_bytes: 640