#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <chrono>
#include <complex>
#include <condition_variable>
#include <deque>
#include <exception>
#include <forward_list>
#include <fstream>
#include <functional>
#include <future>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
//constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

// https://atcoder.jp/contests/abc137/tasks/abc137_e
class BellmanFord {

public:
  struct Edge {
    int from;
    int to;
    ll cost;

    Edge(int from_, int to_, ll cost_)
      : from(from_), to(to_), cost(cost_) {}
  };

  const int N; // number of nodes
  vll d; // distance of each node
  vi predecessors;
  vector<Edge> edges;

  vvi toNodes; // from node -> to node
  vvi otNodes; // to node -> from

  vector<bool> ok;

  explicit BellmanFord(int N_) :
	  N(N_), d(N, LINF), predecessors(N, -1),
	  edges(), toNodes(N_), otNodes(N_),
	  ok(N) { }

  // Add a directed edge.
  // For an undirected graph, the caller should add both directions.
  void add_edge(int from, int to, ll cost) {
    edges.emplace_back(from, to, cost);
    toNodes[from].emplace_back(to);
    otNodes[to].emplace_back(from);
  }

  void relaxing() {
    for (Edge& e : edges) {
      if (!ok[e.from] || !ok[e.to]) continue;

      if (d[e.from] < LINF && d[e.from]+e.cost < d[e.to]) {
        d[e.to] = d[e.from] + e.cost;
	predecessors[e.to] = e.from;
      }
    }
  }

  void dfs(int v, const vvi& links, vector<bool>& visited) {
    visited[v] = true;
    for (auto u : links[v]) {
      if (visited[u]) continue;
      visited[u] = true;
      dfs(u, links, visited);
    }
  }

  void run(int start) {
    d[start] = 0;

    // reachable from the start node
    vector<bool> toReachables(N);
    dfs(start, toNodes, toReachables);

    vector<bool> otReachables(N);
    dfs(N-1, otNodes, otReachables);

    for (int i=0; i<N; i++) {
      ok[i] = toReachables[i] & otReachables[i];
    }

    for (int i=0; i<N-1; i++) {
      relaxing();
    }
  }

  bool hasNegativeCycle() {
    for (Edge& e : edges) {
      if (!ok[e.from] || !ok[e.to]) continue;

      if (d[e.from] + e.cost < d[e.to]) {
	return true;
      }
    }

    return false;
  }

};

int N, M, P;

int main(int argc, char** argv) {
  cin >> N >> M >> P;

  BellmanFord bf(N);

  for (int i=0; i<M; i++) {
    int A, B, C;
    cin >> A >> B >> C;
    A--; B--; // 0-indexed
    bf.add_edge(A, B, -(C-P));
  }

  bf.run(0);

  // check cycle on path from 0 to N-1
  if (bf.hasNegativeCycle()) {
    cout << -1 << endl;
    return 0;
  }

  cout << max({0LL, -bf.d[N-1]}) << endl;

  return 0;
}


Measured memory_bytes: 768