#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)2e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

const ll MAX_V = 200010;

struct edge
{
  ll from, to;
  ll cost;
};

class BellmanFord
{
public:
  ll V;
  vector<edge> E;
  ll d[MAX_V];

  BellmanFord(ll V_num) : V(V_num)
  {
  }

  void calc(ll s)
  {
    rep(i, V + 1) d[i] = LINF;
    d[s] = 0;
    bool update;
    while (1)
    {
      update = false;
      for (auto e : E)
      {
        if (d[e.from] != LINF && d[e.to] > d[e.from] + e.cost)
        {
          d[e.to] = d[e.from] + e.cost;
          update = true;
        }
      }
      if (!update)
        return;
    }
  }

  bool calc_and_find_negative_loop(ll s, ll g)
  {
    ll negative[MAX_V];
    rep(i, V + 1) d[i] = LINF;
    d[s] = 0;

    rep(i, V)
    {
      bool update = false;
      for (auto e : E)
      {
        if (d[e.from] != LINF && d[e.to] > d[e.from] + e.cost)
        {
          d[e.to] = d[e.from] + e.cost;
          update = true;
          if (i == V - 1)
            negative[e.from] = negative[e.to] = true;
        }
      }
      if (!update)
        return false;
    }
    return negative[g];
  }

  bool find_any_negative_loop()
  {
    ll d_[MAX_V];
    rep(i, V) for (auto e : E)
    {
      if (d_[e.to] > d_[e.from] + e.cost)
      {
        d_[e.to] = d_[e.from] + e.cost;
        if (i == V - 1)
          return true;
      }
    }
    return false;
  }
};

inline void finish()
{
  cout << -1 << endl;
  exit(0);
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  ll n, m, p;
  cin >> n >> m >> p;
  vector<ll> E[5010], E_rev[5010];
  vector<edge> E_log;
  rep(i, m)
  {
    ll a, b, c;
    cin >> a >> b >> c;
    a--, b--, c = p - c;
    E_log.push_back({a, b, c});
    E[a].push_back(b);
    E_rev[b].push_back(a);
  }

  bool s[2510] = {}, g[2510] = {};
  s[0] = g[n - 1] = true;

  queue<ll> que;
  que.push(0);
  while (!que.empty())
  {
    ll q = que.front();
    que.pop();
    for (auto to : E[q])
    {
      if (!s[to])
      {
        que.push(to);
        s[to] = true;
      }
    }
  }

  que.push(n - 1);
  while (!que.empty())
  {
    ll q = que.front();
    que.pop();
    for (auto to : E_rev[q])
    {
      if (!g[to])
      {
        que.push(to);
        g[to] = true;
      }
    }
  }

  BellmanFord bf(n);

  for (auto e : E_log)
  {
    if (s[e.from] && g[e.to])
      bf.E.push_back(e);
  }

  if (bf.find_any_negative_loop())
    finish();
  bf.calc(0);
  cout << max(0LL, -bf.d[n - 1]) << endl;
  return 0;
}


Measured memory_bytes: 3200