#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;
#define int long long
const int mod = 1e9 + 7;

const int inf = 1e18;

int add(int x, int y) {
    return (1ll * x + 1ll * y) % mod;
}

int del(int x, int y) {
    return ((1ll * x - 1ll * y) % mod + mod) % mod;
}

int mul(int x, int y) {
    return (1ll * x * 1ll * y) % mod;
}

const int N = 2500 + 5;
int n, m, p;
vector<ii> graph[N];
stack<int> st;
bool stackmember[N], vis[N], lmao[N];
int dist[N];
int low[N], num[N], times = 0;

vector<int> vec;
bool check[N];

void dfs(int u) {
    vis[u] = 1;
    low[u] = num[u] = times++;
    st.push(u);
    stackmember[u] = 1;
    for(int i = 0; i < graph[u].size(); i++) {
        ii v = graph[u][i];
        if(!vis[v.fi]) {
            dfs(v.fi);
            low[u] = min(low[u], low[v.fi]);
        }
        else if(stackmember[v.fi])
            low[u] = min(low[u], num[v.fi]);
    }
    if(low[u] == num[u]) {
        lmao[u] = 1;
        vec.clear();
        vec.pb(u);
        while(!st.empty() && st.top() != u) {
            stackmember[st.top()] = 0;
            lmao[st.top()] = 1;
            vec.pb(st.top());
            st.pop();
        }
        st.pop();
        stackmember[u] = 0;
        for(int i = 0; i < vec.size(); i++)
            dist[vec[i]] = -inf;
        dist[u] = 0;
        for(int j = 1; j <= n; j++) {
            for(int o = 0; o < vec.size(); o++) {
                int i = vec[o];
                if(!lmao[i]) continue;
                for(int l = 0; l < graph[i].size(); l++) {
                    int v = graph[i][l].fi;
                    if(dist[i] == -inf) continue;
                    if(lmao[v])
                        dist[v] = max(dist[v], dist[i] + graph[i][l].se);
                }
            }
        }
        int ck = 0;
        for(int o = 0; o < vec.size(); o++) {
            int i = vec[o];
            if(!lmao[i]) continue;
            for(int l = 0; l < graph[i].size(); l++) {
                int v = graph[i][l].fi;
                if(dist[i] == -inf) continue;
                if(!lmao[v]) continue;
                //cout << dist[i] << " " << dist[v] << " " << graph[i][l].se << " " << u << "\n";
                if(dist[i] + graph[i][l].se > dist[v])
                   ck = 1;
            }
        }
        //cout << ck << "\n";
        if(ck && check[u]) {
            cout << "-1";
            exit(0);
        }
        for(int i = 0; i < vec.size(); i++)
            dist[vec[i]] = 0, lmao[vec[i]] = 0;
        vec.clear();
    }
}

vector<int> rv[N];

void rfs(int u) {
    check[u] = 1;
    for(int i = 0; i < rv[u].size(); i++) {
        int v = rv[u][i];
        if(check[v]) continue;
        rfs(v);
    }
}

signed main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n >> m >> p;
    for(int i = 1; i <= m; i++) {
        int u, v, c;
        cin >> u >> v >> c; c -= p;
        graph[u].pb({v, c});
        rv[v].pb(u);
    }
    rfs(n);
    dfs(1);
    for(int i = 1; i <= n; i++)
        dist[i] = -inf;
    dist[1] = 0;
    for(int j = 1; j <= n + m; j++) {
        for(int i = 1; i <= n; i++) {
            for(int l = 0; l < graph[i].size(); l++) {
                int v = graph[i][l].fi;
                if(dist[i] != -inf)
                    dist[v] = max(dist[v], dist[i] + graph[i][l].se);
            }
        }
    }
    cout << max(dist[n], 0ll);
}



Measured memory_bytes: 896