#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

template<class T>
struct BellmanFord {
private:
    struct Edge { int to, cost; };
    int n;
    vector<vector<Edge>> edges;
    vector<vector<bool>> reachable;
    
    void get_reachable_dfs(int from, int to) {
        if (reachable[from][to]) return;
        reachable[from][to] = true;
        for (auto e : edges[to]) {
            get_reachable_dfs(from, e.to);
        }
    }
    
    bool is_reachable(int from, int to) {
        if (reachable.size() == 0) {
            reachable.resize(n, vector<bool>(n, false));
            for (int i = 0; i < reachable.size(); i++) {
                get_reachable_dfs(i, i);
            }
        }
        return reachable[from][to];
    }
    
public:
    const T inf = numeric_limits<T>::max() / 2 - 1;
    vector<T> dist;
    vector<bool> negative;
    
    BellmanFord() {}
    BellmanFord(int _n) : edges(_n), dist(_n), negative(_n) {
        n = _n;
    }
    
    void add_edge(int from, int to, int cost) {
        edges[from].push_back((Edge){to, cost});
    }
    
    void get_distance(int _from, int _to = -1) {
        for (int i = 0; i < n; i++) {
            dist[i] = inf;
            negative[i] = false;
        }
        dist[_from] = 0;
        for (int i = 0; i < (n - 1); i++) {
            for (int from = 0; from < n; from++) {
                for (int j = 0, el = sz(edges[from]); j < el; j++) {
                    int to = edges[from][j].to;
                    int cost = edges[from][j].cost;
                    if ((dist[from] != inf) && (dist[to] > (dist[from] + cost))) {
                        dist[to] = dist[from] + cost;
                    }
                }
            }
        }
        vector<T> tmp(n);
        for (int i = 0; i < n; i++) tmp[i] = dist[i];
        for (int i = 0; i < n; i++) {
            for (int from = 0; from < n; from++) {
                for (int j = 0, el = sz(edges[from]); j < el; j++) {
                    int to = edges[from][j].to;
                    int cost = edges[from][j].cost;
                    if ((tmp[from] != inf) && (tmp[to] > (tmp[from] + cost))) {
                        tmp[to] = tmp[from] + cost;
                        negative[from] = negative[to] = true;
                    }
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if ((is_reachable(_from, i)) && (tmp[i] != dist[i])) {
                if (_to == -1) {
                    negative[_from] = negative[i] = true;
                }
                else if (is_reachable(i, _to)) {
                    negative[_from] = negative[_to] = negative[i] = true;
                }
            }
        }
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m, p;
    cin >> n >> m >> p;
    BellmanFord<ll> bf(n);
    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        c = (c - p) * -1;
        bf.add_edge(a, b, c);
    }
    bf.get_distance(0, n - 1);
    if (bf.negative[n - 1]) {
        cout << -1 << endl;
    }
    else {
        cout << max(0LL, bf.dist[n - 1] * -1) << endl;
    }
    return 0;
}


Measured memory_bytes: 1408