#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
using CostType = long long;
struct Edge {
  int src, dst; CostType cost;
  Edge(int src, int dst, CostType cost = 0) : src(src), dst(dst), cost(cost) {}
  inline bool operator<(const Edge &rhs) const {
    return cost != rhs.cost ? cost < rhs.cost : dst != rhs.dst ? dst < rhs.dst : src < rhs.src;
  }
  inline bool operator<=(const Edge &rhs) const { return cost <= rhs.cost; }
  inline bool operator>(const Edge &rhs) const {
    return cost != rhs.cost ? cost > rhs.cost : dst != rhs.dst ? dst > rhs.dst : src > rhs.src;
  }
  inline bool operator>=(const Edge &rhs) const { return cost >= rhs.cost; }
};

struct BellmanFord {
  vector<CostType> dist;

  BellmanFord(const vector<vector<Edge> > &graph, const CostType CINF = LINF) : graph(graph), CINF(CINF) {}

  bool has_negative_cycle(int s) {
    int n = graph.size();
    dist.assign(n, CINF);
    dist[s] = 0;
    prev.assign(n, -1);
    REP(step, n) {
      bool is_updated = false;
      REP(i, n) for (Edge e : graph[i]) {
        if (dist[i] != CINF && dist[e.dst] > dist[i] + e.cost) {
          dist[e.dst] = dist[i] + e.cost;
          prev[e.dst] = i;
          is_updated = true;
        }
      }
      if (!is_updated) return false;
    }
    return true;
  }

  vector<int> build_path(int t) {
    vector<int> res;
    for (; t != -1; t = prev[t]) res.emplace_back(t);
    reverse(ALL(res));
    return res;
  }

private:
  vector<vector<Edge> > graph;
  const CostType CINF;
  vector<int> prev;
};

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m, p; cin >> n >> m >> p;
  vector<vector<Edge> > check1(n), check2(n), graph(n);
  while (m--) {
    int a, b, c; cin >> a >> b >> c; --a; --b;
    check1[b].emplace_back(Edge(b, a, p - c));
    check2[a].emplace_back(Edge(a, b, p - c));
  }
  vector<bool> can_goal(n, false);
  queue<int> que;
  que.emplace(n - 1);
  can_goal[n - 1] = true;
  while (!que.empty()) {
    int ver = que.front(); que.pop();
    for (Edge e : check1[ver]) if (!can_goal[e.dst]) {
      can_goal[e.dst] = true;
      que.emplace(e.dst);
    }
  }
  vector<bool> used(n, false);
  que.emplace(0);
  used[0] = true;
  while (!que.empty()) {
    int ver = que.front(); que.pop();
    for (Edge e : check2[ver]) if (can_goal[e.dst]) {
      graph[e.src].emplace_back(e);
      if (!used[e.dst]) {
        used[e.dst] = true;
        que.emplace(e.dst);
      }
    }
  }
  BellmanFord bf(graph);
  if (bf.has_negative_cycle(0)) {
    cout << -1 << '\n';
    return 0;
  }
  cout << max(-bf.dist[n - 1], 0LL) << '\n';
  return 0;
}


Measured memory_bytes: 1024