#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

struct edge {
    int from, to, cost;
    edge(int from, int to, int cost): from(from), to(to), cost(cost) {}
};

class UnionFind {
    struct UFNode {
        int par;
        int rank;
    };
    vector<UFNode> nodes;
public:
    UnionFind(int n): nodes(n) {
        for (int i = 0; i < n; i++) {
            nodes[i].par = i;
            nodes[i].rank = 0;
        }
    };
    int root(int x) {
        return nodes[x].par == x ? x : root(nodes[x].par);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (nodes[x].rank < nodes[y].rank) {
            nodes[x].par = y;
        } else {
            nodes[y].par = x;
            if (nodes[x].rank == nodes[y].rank) nodes[x].rank++;
        }
    }
    //~UnionFind() {cout << nodes.size() << endl;}
};

void solve() {
    LL n,m,p;
    cin >> n >> m >> p;
    vector<edge> es;
    VVI fs(n), bs(n);
    int a,b,c;
    REP(i,0,m) {
        cin >> a >> b >> c;
        --a; --b;
        es.pb(a,b,-(c-p));
        fs[a].pb(b);
        bs[b].pb(a);
    }
    UnionFind uf(n), ub(n);
    { // 1 ->
        deque<int> q;
        vector<bool> v(n);
        q.push_back(0);
        while (!q.empty()) {
            int src = q.front();
            q.pop_front();
            if (v[src]) continue;
            v[src] = true;
            for (auto &&dst: fs[src]) {
                if (uf.same(src,dst)) continue;
                uf.unite(src,dst);
                q.push_back(dst);
            }
        }
    }
    { // N ->
        deque<int> q;
        vector<bool> v(n);
        q.push_back(n-1);
        while (!q.empty()) {
            int src = q.front();
            q.pop_front();
            if (v[src]) continue;
            v[src] = true;
            for (auto &&dst: bs[src]) {
                if (ub.same(src,dst)) continue;
                ub.unite(src,dst);
                q.push_back(dst);
            }
        }
    }
    VI d(n, 1<<30);
    d[0] = 0;
    REP(i,0,n) {
        for (auto &&e: es) {
            int src = e.from, dst = e.to, cost = e.cost;
            if (d[dst] > d[src] + cost) {
                d[dst] = d[src] + cost;
            }
        }
    }

    for (auto &&e: es) {
        int src = e.from, dst = e.to, cost = e.cost;
        if (d[dst] > d[src] + cost) {
            if (uf.same(0,src) && ub.same(n-1,dst)) {
                cout << -1 << endl;
                return;
            }
        }
    }
    cout << max(0, -d[n-1]) << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 640