//
// Created by Koki Igarashi on 7/27/20.
//

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int, Int> pii;
typedef pair<Int, double> pid;
typedef pair<double, double> pdd;
typedef pair<Int, pii> pip;
typedef pair<pii, Int> ppi;
typedef pair<double, Int> pdp;
typedef vector<Int> veci;
typedef vector<double> vecd;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<pii> vecpii;
typedef vector<ppi> vecppi;
typedef vector<veci> mati;
typedef vector<vecll> matll;
typedef vector<vecd> matd;
#define PB(x) push_back(x)
#define EB(x) emplace_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define REP(i, a, b) for(int i = (a);i <= (b);i++)
#define FORO(i, n) REP(i,0,(int)n-1)
#define FORI(i, n) REP(i,1,(int)n)
#define FORIT(i, t) for(auto i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a, _b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
#define DEBUG 1
#if DEBUG
#define DUMP(a) do { std::cout << #a " = " << (a) << ", "; } while(false)
#define DUMPLN(a) do { std::cout << #a " = " << (a) << std::endl; } while(false)
#else
#define DUMP(a)
#define DUMPLN(a)
#endif
template<typename T, typename U>
inline void getMin(T &a, U b) { if (a > b) a = b; }
template<typename T, typename U>
inline void getMax(T &a, U b) { if (a < b) a = b; }
template<typename T>
vector<T> getVector(const int n) { return vector<T>(n); }
template<typename T>
vector<T> getVector(const int n, const T a) { return vector<T>(n, a); }
template<typename T>
vector<T> getEmptyVector() { return vector<T>(); }
template<typename T>
void appendAll(vector<T> &a, vector<T> b) { a.insert(a.end(), b.begin(), b.end()); }
// #define X first
// #define Y second
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const ll MOD = 1000000007;
const int MAXN = 1 << 17;
const int inf = 1 << 20;
const ll llinf = 1LL<<50LL;
const int NIL = -inf;
int popcount(int x) { return __builtin_popcount(x); }

int N, M, P;
vector<vector<pii>> G;
vecll D;

bool dfs(int u, veci &rechable, veci &used) {
    if(u == N - 1) return true;
    if(used[u]) return rechable[u];
    rechable[u] = 0;
    used[u] = 1;
    for(auto e : G[u]) {
        if(dfs(e.first, rechable, used)) {
            rechable[u] = 1;
            return true;
        }
    }
    return false;
}

bool bellman_ford(int s) {
    veci pre(N);
    veci in_positive_cycle(N);
    D[s] = 0;
    pre[s] = -1;
    FORO(k,  2 * M) {
        FORO(u, N) {
            if(D[u] <= -llinf) continue;
            for(auto e : G[u]) {
                int v = e.first;
                ll c = e.second - P;
                if (D[v] < D[u] + c) {
                    D[v] = D[u] + c;
                    pre[v] = u;
                    if (k >= N - 1) {
                        in_positive_cycle[v] = 1;
                    }
                }
            }
        }
    }
    FORO(i, N) {
        veci reachable(N), used(N);
        if(dfs(i, reachable, used) && in_positive_cycle[i]) {
            return false;
        }
    }
    return true;
}

int solve() {
    D.assign(N, -llinf);
    if(!bellman_ford(0)) return -1;
    // FORO(i, N) { DUMP(i); DUMPLN(D[i]); }
    if(D[N - 1] <= -llinf) return -1;
    return max(0LL, D[N - 1]);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> M >> P;
    G.resize(N);
    FORO(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].EB(pii(b, c));
        // G[b].EB(pii(a, c));
    }

    cout << solve() << endl;

    return 0;
}

Measured memory_bytes: 3948