#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}


//頂点数がn,枝数がm
//bellman_ford bf(n,m);
//適宜add_edge
//bf.comp(出発点)でdに最短路長が入る
//負の有向閉路には3種類存在することに注意する

template<typename T> class bellman_ford {
public:
    struct edge{
        int from, to;
        T cost;
    };
    int V;
    T inf;
    vector<T> d;
    vector<edge> es;
    bellman_ford(int node_size) : V(node_size), inf(numeric_limits<T>::max()/2), d(V, inf){}
    void add_edge(int from, int to, T cost){
        es.push_back((edge){from, to, cost});
    }
    //sからの最短路長およびsからたどり着ける負の閉路の検出(trueなら負の閉路が存在する)
    bool solve(int s){
        int cnt = 0;
        d[s] = 0;
        while(cnt < V){
            bool update = false;
            for(auto& e : es){
                if(d[e.from] != inf && d[e.to] > d[e.from] + e.cost){
                    d[e.to] = d[e.from] + e.cost;
                    update = true;
                }
            }
            if(!update) break;
            cnt++;
        }
        return (cnt == V);
    }
    //すべての負の閉路の検出(trueなら負の閉路が存在する)
    bool find_negative_loop(){
        fill(d.begin(), d.end(), (T)0);
        int cnt = 0;
        while(cnt < V){
            bool update = false;
            for(auto& e : es){
                if(d[e.to] > d[e.from] + e.cost){
                    d[e.to] = d[e.from] + e.cost;
                    update = true;
                }
            }
            if(!update) break;
            cnt++;
        }
        return (cnt == V);
    }
    // s, t 間の最短距離が非有界
    bool shortest_path_infinite(int s, int t){
        d[s] = 0;
        for(int i = 0; i < 2*V-1; i++){
            for(auto& e : es){
                if(d[e.from] != inf && d[e.to] > d[e.from] + e.cost){
                    d[e.to] = d[e.from] + e.cost;
                    if(i >= V-1){
                        if(e.to == t) return true;
                        d[e.to] = -inf;
                    }
                }
            }
        }
        return false;
    }
};

int main() {
    int n, m, p;
    cin >> n >> m >> p;
    bellman_ford<ll>g(n);
    rep(i,m){
        int a, b,c;
        cin >> a >> b >> c;
        a--,b--;
        g.add_edge(a,b,p-c);
    }
    if(!g.shortest_path_infinite(0,n-1)){
        cout << max(0LL,-g.d[n-1]) << endl;
    }else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 512