#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
    struct edge {
        int from, to;
        ll cost;
    };
    vector<edge> es; // 辺
    vector<ll> d; //最短距離,0で初期化してね
    vector<bool> nloop;
    int V, E;//頂点数と辺の数

    bool find_negative_loop(int s) {
        //dはINFで初期化しておく
//        d[s] = 0;
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < E; j++) {
                edge e = es[j];
                if (d[e.from] != INFl && d[e.to] > d[e.from] + e.cost) {
                    d[e.to] = d[e.from] + e.cost;
                    if (i == V - 1 && e.to == V - 1) return true;
                }
            }
        }
        return false;
    }

    bool find_negative_loop2(int s) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < E; j++) {
                edge e = es[j];
                if (d[e.from] != INFl && d[e.to] > d[e.from] + e.cost) {
                    d[e.to] = d[e.from] + e.cost;
                    nloop[e.to] = true;
                    if (i == V - 1 && e.to == V - 1) return true;
                }
            }
        }
        return false;
    }

    bool find_negative_loop3(int s) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < E; j++) {
                edge e = es[j];
                if (d[e.from] != INFl && (d[e.from] == -INFl || nloop[e.to])) {
//                    d[e.to] = d[e.from] + e.cost;
//                    nloop[e.to] = true;
                    d[e.to] = -INFl;
                    if (i == V - 1 && e.to == V - 1) return true;
                }
            }
        }
        return false;
    }

public:
    void solve() {
        ll N, M, P;
        cin >> N >> M >> P;
        V = N;
        E = M;
        d.resize(N, INFl);
        d[0] = 0;
        nloop.resize(N, false);
        for (int i = 0; i < M; ++i) {
            int a, b;
            ll c;
            cin >> a >> b >> c;
            a--, b--;
            es.push_back((edge) {a, b, P - c});
        }

        find_negative_loop(0);
        ll tmp1 = d[N - 1];
        find_negative_loop2(0);
        find_negative_loop3(0);
//        find_negative_loop(0);
        ll tmp2 = d[N - 1];

//        if (tmp1 != tmp2) {
//            cout << -1 << endl;
////            exit(-1);
//        } else {
//            ll ans = max(-tmp1, 0ll);
//            cout << ans << endl;
//        }

        if (tmp2 == -INFl) {
            cout << -1 << endl;
        } else {
            ll ans = max(-tmp1, 0ll);
            cout << ans << endl;
        }

//        if (find_negative_loop(0)) {
//            cout << -1 << endl;
//        } else {
//            ll ans = max(-d[N - 1], 0ll);
//            cout << ans << endl;
//        }


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 512