// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <algorithm>

#include <cmath>

#include <queue>

#include <string>

#include <map>

#include <set>

#include <tuple>

#include <deque>

#include <numeric>

#include <bitset>

#include <iomanip>

#include <cassert>

#include <chrono>

#include <random>

#include <limits>

#include <iterator>

#include <functional>

using namespace std;

 

typedef long long ll;

typedef pair<int, int> P;

const double PI = 3.1415926535897932;   // acos(-1)

const double EPS = 1e-15;

const int mod = 1e+9 + 7;

const int INF = 1001001001;



bool used_1[2505];

bool used_n[2505];

vector<int> graph[2505];

vector<int> rev[2505];

vector<P> edges(5005);

vector<int> cost(5005);

vector<int> dist(2505, INF);

int n, m, p;



void reachable_from_1(int u){

    if(used_1[u])   return;

    used_1[u] = true;

    for(int v : graph[u]){

        reachable_from_1(v);

    }

    return;

}



void reachable_to_n(int u){

    if(used_n[u])   return;

    used_n[u] = true;

    for(int v : rev[u]){

        reachable_to_n(v);

    }

    return;

}



int bellman_ford(int s, int t){

    dist[s] = 0;

    bool update = false;

    for(int i = 0; i < n; ++i){

        update = false;

        for(int j = 0; j < m; ++j){

            int u = edges[j].first;

            int v = edges[j].second;

            if(dist[u] == INF)  continue;

            if(!used_1[u] || !used_1[v] || !used_n[u] || !used_n[v])    continue;

            if(dist[v] > dist[u] + cost[j]){

                dist[v] = dist[u] + cost[j];

                update = true;

            }

        }

    }

    if(update)  return -1;

    return max(0, -dist[t]);

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    cin >> n >> m >> p;

    for(int i = 0; i < m; ++i){

        int a, b;

        cin >> a >> b >> cost[i];

        --a, --b;

        cost[i] -= p;

        cost[i] *= -1;

        graph[a].push_back(b);

        rev[b].push_back(a);

        edges[i] = P(a, b);

    }

    reachable_from_1(0);

    reachable_to_n(n-1);

    cout << bellman_ford(0, n-1) << endl;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <algorithm>

#include <cmath>

#include <queue>

#include <string>

#include <map>

#include <set>

#include <stack>

#include <tuple>

#include <deque>

#include <numeric>

#include <bitset>

#include <iomanip>

#include <cassert>

#include <chrono>

#include <random>

#include <limits>

#include <iterator>

#include <functional>

#include <sstream>

#include <complex>

using namespace std;



typedef long long ll;

typedef uint64_t ull;

typedef pair<int, int> P;

constexpr double EPS = 1e-9;

constexpr int INF = 1001001001;

constexpr int mod = 1000000007;

// constexpr int mod = 998244353;



#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int n, m, p;

    cin >> n >> m >> p;

    vector<tuple<int, int, int>> es;

    vector<vector<int>> graph(n);

    vector<vector<int>> rev(n);

    for(int i = 0; i < m; ++i){

        int a, b, c;

        cin >> a >> b >> c;

        --a, --b;

        es.emplace_back(a, b, p - c);

        graph[a].emplace_back(b);

        rev[b].emplace_back(a);

    }



    vector<bool> visited(n, false);

    vector<bool> rev_visited(n, false);



    auto dfs = [](auto&& self, vector<vector<int>>& g, vector<bool>& memo, int from) -> void {

        if(memo[from])  return;

        memo[from] = true;

        for(int to : g[from]){

            self(self, g, memo, to);

        }

        return;

    };

    dfs(dfs, graph, visited, 0);

    dfs(dfs, rev, rev_visited, n - 1);



    vector<bool> used(n);

    for(int i = 0; i < n; ++i){

        used[i] = visited[i] && rev_visited[i];

    }



    constexpr ll inf = 1e+11;

    vector<ll> dist(n, inf);

    dist[0] = 0;

    bool update = false;

    for(int loop = 0; loop < n; ++loop){

        update = false;

        for(int i = 0; i < m; ++i){

            int u, v, cost;

            tie(u, v, cost) = es[i];

            if(!used[u] || !used[v])    continue;

            if(dist[v] > dist[u] + cost){

                dist[v] = dist[u] + cost;

                update = true;

            }

        }

    }



    ll ans = max(0LL, -dist[n - 1]);

    if(update)  ans = -1;

    cout << ans << endl;

}

// Fastest known solution for this problem: