#include <bits/stdc++.h>
using namespace std;

#define range(i, l, r) for (int i = (int)l; i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = ((int)(r) - 1); i >= (int)l; --(i))

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int mod     = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(16); cerr << fixed << setprecision(16); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename cost_type > class bellman_ford {

  struct edge {
    edge() {}
    edge(int from, int to, cost_type cost) : from(from), to(to), cost(cost) {}

    int from, to;
    cost_type cost;
  };

  int V;
  cost_type max_cost;
  vector< cost_type > dist_;
  vector< bool > on_nc;
  vector< edge > edges;
  vector< vector< int > > G;

public:

  bellman_ford(int size_, cost_type max_cost) : V(size_), max_cost(max_cost), dist_(V, max_cost), on_nc(V, false), G(V) {}

  void add_edge(int from, int to, cost_type cost) {
    edges.emplace_back(edge(from, to, cost));
    G[from].push_back(to);
  }

  void build(int st) {
    dist_[st] = 0;
    for (int i = 0; i < V - 1; ++i) {
      for (auto &e : edges) {
        if (dist_[e.from] == max_cost) continue;
        if (dist_[e.to] > dist_[e.from] + e.cost) dist_[e.to] = dist_[e.from] + e.cost;
      }
    }
    
    queue< int > nc;
    for (auto &e : edges) {
      if (dist_[e.from] == max_cost) continue;
      if (dist_[e.to] > dist_[e.from] + e.cost) nc.push(e.to);
    }

    while (!nc.empty()) {
      int v = nc.front();
      nc.pop();

      if (on_nc[v]) continue;
      on_nc[v] = true;
      for (auto to : G[v]) nc.push(to);
    }
  }

  bool is_negative_cycle(int v) {
    return on_nc[v];
  }

  cost_type dist(int v) {
    return dist_[v];
  }
};

void solver() {
  int N = input(), M = input(), P = input();

  bellman_ford< int > G(N, inf);
  range(i, 0, M) {
    int a = input() - 1, b = input() - 1, c = input();
    G.add_edge(a, b, P - c);
  }

  G.build(0);

  if (G.is_negative_cycle(N - 1)) {
    cout << -1 << endl;
  } else {
    cout << max(0, -G.dist(N - 1)) << endl;
  }
}

signed main(int argc, char *argv[]) {
  solver();
}


Measured memory_bytes: 512