#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
}
using namespace utils;


void sub_main(istream &is) {
    ll N, M, P;
    is >> N >> M >> P;
    if(!is) return;
    vector<ll> dist(N, -INF);
    dist[0] = 0;
    vector<tuple<int, int, ll>> edge;
    unordered_map<int, unordered_set<int>> ch, par;
    for (int i = 0; i < M; ++i) {
        int a, b, c;
        is >> a >> b >> c;
        a--; b--;
        edge.emplace_back(a, b, c-P);
        ch[a].insert(b);
        par[b].insert(a);
    } // end i
    vector<bool> scan(N, false), ecan(N, false);
    scan[0] = true;
    queue<int> bfq;
    bfq.push(0);
    while(!bfq.empty()){
        int t = bfq.front(); bfq.pop();
        for (auto &&x : ch[t]) {
            if(!scan[x]){
                scan[x] = true;
                bfq.push(x);
            }
        } // end x
    }

    ecan[N-1] = true;
    bfq.push(N-1);
    while(!bfq.empty()){
        int t = bfq.front(); bfq.pop();
        for (auto &&x : par[t]) {
            if(!ecan[x]){
                ecan[x] = true;
                bfq.push(x);
            }
        } // end x
    }



    bool exist;
    ll loop = 0;
    while(loop < N){
        bool update = false;
        for (int j = 0; j < M; ++j) {
            auto e = edge[j];
            int a, b, c;
            tie(a, b, c) = e;
            if(scan[b] and ecan[b])
                if(dist[a] != -INF and
                    max_update(dist[b], dist[a] + c)){
                update = true;
            }
        } // end j
        if(!update) break;
        loop++;
    } // end i
    exist = loop != N;

    if(exist){
        cout << max(ll{0}, dist[N-1]) << endl;
    }
    else {
        cout << -1 << endl;
    }


}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_E.txt";
    cerr << "DEBUG MODE" <<  endl;
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 1408