/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 100100100100100100;
const int MOD = 1000000007;
const int inf = 1001001001;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

vector<pair<pair<int,int>,long long>> Edge;
vector<long long> score(3000,-INF);
vector<vector<int>> graph_from1(3000);
vector<vector<int>> graph_toN(3000);
vector<bool> canReach_from1(3000);
vector<bool> canReach_toN(3000);

void dfs_from1(int now){
    canReach_from1.at(now) = true;
    for(int to : graph_from1.at(now)){
        if(canReach_from1.at(to)) continue;
        dfs_from1(to);
    }
}

void dfs_toN(int now){
    canReach_toN.at(now) = true;
    for(int to : graph_toN.at(now)){
        if(canReach_toN.at(to)) continue;
        dfs_toN(to);
    }
}

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

    int N,M;long long P;cin >> N >> M >> P;
    for(int i = 0;i<M;i++){
        int from,to;long long coin;cin >> from >> to >> coin;
        from--;to--;
        //T分*P円払うんだったら予め全辺P引いといたら最後払わなくてもいい
        coin -= P;
        Edge.push_back(make_pair(make_pair(from,to),coin));
        graph_from1.at(from).push_back(to);
        graph_toN.at(to).push_back(from);
    }

    //始点と終点両方から辿り着けない頂点は無視する→関係ない閉路も無視できる
    //→あとは普通にベルマンフォードするだけ
    dfs_from1(0);
    dfs_toN(N-1);
    vector<bool> observeNode(N);
    for(int i = 0;i<N;i++) if(canReach_from1.at(i) && canReach_toN.at(i)) observeNode.at(i) = true;

    //ベルマンフォード
    score.at(0) = 0;
    long long prv = -INF;
    
    for(int i = 0;i<N+5;i++){
        prv = score.at(N-1);
        bool update = false;
        for(int j = 0;j<M;j++){
            int from,to;long long coin;
            from = Edge.at(j).first.first,to = Edge.at(j).first.second,coin = Edge.at(j).second;
            if(score.at(from) == -INF) continue;
            if(!observeNode.at(from) || !observeNode.at(to)) continue;
            if(score.at(from)+coin > score.at(to)){
                score.at(to) = score.at(from)+coin;
                update = true;
            }
        }
        if(!update) break;
        if(i > N){
            //関係ある閉路だけ残したので、1→Nに閉路があれば絶対-1
            cout << -1 << endl;
            return 0;
        }
    }
    cout << max(score.at(N-1),(long long)0) << endl;
}

Measured memory_bytes: 4096