#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template <typename T> using order_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T1, typename T2> using order_map = tree <T1, T2, less <T1>, rb_tree_tag, tree_order_statistics_node_update>;

template <class T> bool MIN(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool MAX(T &a, T b) { return a < b ? (a = b, true) : false; }

#define ll              long long int
#define endl            '\n'
#define pii             pair <int, int>
#define pll             pair <ll, ll>
#define mk              make_pair
#define ff              first
#define ss              second
#define all(a)          (a).begin(), (a).end()
#define rall(a)         (a).rbegin(), (a).rend()
#define eb              emplace_back
#define pb              push_back
#define LINE            __LINE__

static const int maxn = 2500 + 5;
static const int logn = 19;
static const ll inf = 1e18;

struct Node {
      int v, w;
      Node(int v = 0, int w = 0)
            : v(v), w(w) {}
};

vector < vector <Node> > graph;
bool inQueue[maxn];
ll dist[maxn];
int cnt[maxn];
int n;
int m;
int p;
int bad[maxn];

int spfa(int src = 1) {
      for (int i = 1; i < maxn; i++) {
            dist[i] = inf;
      }
      queue <int> pq;
      pq.emplace(src);
      dist[src] = 0;
      inQueue[src] = 1;
      cnt[src] = 1;
      while (pq.size()) {
            int u = pq.front(); pq.pop();
            inQueue[u] = 0;
            if (cnt[u] > n) {
                  return -1;
            }
            for (Node it : graph[u]) {
                  int v = it.v;
                  int w = it.w;
                  if (bad[v] == 1) {
                        continue;
                  }
                  if (dist[v] > dist[u] + w) {
                        dist[v] = dist[u] + w;
                        if (inQueue[v] == 0) {
                              cnt[v]++;
                              inQueue[v] = 1;
                              pq.emplace(v);
                        }
                  }
            }
      }
      if (dist[n] == inf) {
            return -1;
      }
      return 1;
}

int vis[maxn];

int solve(int u) {
      memset(vis, 0, sizeof vis);
      queue <int> pq;
      pq.push(u);
      vis[u] = 1;
      while (pq.size()) {
            int u = pq.front(); pq.pop();
            for (Node it : graph[u]) {
                  int v = it.v;
                  if (vis[v] == 1) {
                        continue;
                  }
                  vis[v] = 1;
                  pq.push(v);
            }
      }
      return vis[n];
}

signed main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);

      cin >> n >> m >> p;
      graph.resize(n + 1);
      for (int e = 1; e <= m; e++) {
            int u, v, w;
            cin >> u >> v >> w;
            w -= p;
            w *= -1;
            graph[u].eb(v, w);
      }
      for (int i = 1; i <= n; i++) {
            if (solve(i) == 0) {
                  bad[i] = 1;
            }
      }
      int ncycle = spfa();
      cout << (ncycle == -1 ? ncycle : max(0LL, -dist[n])) << endl;

      #ifndef ONLINE_JUDGE
            cerr << endl << "Time : " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
      #endif // ONLINE_JUDGE
}


Measured memory_bytes: 512