#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

ll n, m, p;

struct BellmanFord {
    struct edge{
        int from, to; ll cost;
    };
    int N, M;
    vector<edge> E;
    vector<ll> dis;
    const ll INF = 1e18;
    void DirectedInit(int n, int m) {
        N = n;
        M = m;
        E.resize(M);
        dis.assign(N, INF);
        for(int i = 0; i < M; i++) {
            int a, b; ll c;
            cin >> a >> b >> c;
            a--, b--;
            edge e = {a, b, -(c-p)};
            E[i] = e;
        }
    }

    bool build(int s) {
        dis[s] = 0;
        bool update = false;
        for(int i = 0; i < N; i++) {
            update = false;
            for(int j = 0; j < M; j++) {
                edge e = E[j];
                int from = e.from;
                int to = e.to;
                ll cost = e.cost;
                if(dis[from] != INF && dis[from] + cost < dis[to]) {
                    update = true;
                    dis[to] = dis[from] + cost;
                }
            }
            if(update && i == N-1) return true;
            if(!update) break;
        }
        return false;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> p;
    BellmanFord g;
    g.DirectedInit(n, m);
    g.build(0);
    vector<bool> ng(n, false);
    rep(i, n) rep(j, m) {
        ll a = g.E[j].from;
        ll b = g.E[j].to;
        ll c = g.E[j].cost;
        if(g.dis[a] == g.INF) continue;
        if(g.dis[a] + c < g.dis[b]) {
            g.dis[b] = g.dis[a] + c;
            ng[b] = true;
        }
        if(ng[a]) ng[b] = true;
    }
    if(ng[n-1]) cout << -1 << endl;
    else cout << max(0LL, -g.dis[n-1]) << endl;
}


Measured memory_bytes: 3760