#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

// snukeさんのmodint
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// mint N;

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

// combination c(N);
// mint ans = c(N,n);
// cout << ans.x << endl;
// Nとnはll型(mintではない)
// -------------------------------------------------------------



int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,M,p;
    cin >> N >> M >> p;
    vector<ll> d(N,INF);
    d[0] = 0;
    vector<pair<ll,P>> edge(M);
    for(int i=0; i<M; i++){
        ll a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        edge[i] = make_pair(p-c,make_pair(a,b));
    }
    vector<bool> dist(N,false);
    vector<bool> dist2(N,false);
    dist2[N-1] = true;
    dist[0] = true;
    queue<int> que;
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            if(dist[edge[j].second.first]) dist[edge[j].second.second] = true;
            if(dist2[edge[j].second.second]) dist2[edge[j].second.first] = true;
        }
    }
    for(int i=0; i<N*3; i++){
        for(int j=0; j<M; j++){
            auto now = edge[j];
            if(d[now.second.second] > d[now.second.first] + now.first){
                d[now.second.second] = d[now.second.first] + now.first;
                if(i > N-1 and dist[now.second.first] and dist2[now.second.second]){
                    cout << -1 << enld;
                    return 0;
                }
            }
        }
    }
    if(d[N-1] > 0){
        cout << 0 << enld;
    }else{
        cout << -d[N-1] << enld;
    }
    return 0;
}

Measured memory_bytes: 384