#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

struct Graph {
    long long V;
    long long E;
    //u,v,weight,cap
    vector<tuple<long long, long long, long long, long long>> edges;
    void add(long long u, long long v) { edges.push_back(make_tuple(u, v, 1, 1)); }
    void add(long long u, long long v, long long weight) { edges.push_back(make_tuple(u, v, weight, 1)); }
    void add(long long u, long long v, long long weight, long long capacity) { edges.push_back(make_tuple(u, v, weight, capacity)); }
    Graph(long long V) : V(V) {}
    Graph(long long V, long long E) : V(V), E(E) {}
};

//ワーシャルフロイド法(負閉路検出時はv[0].size()が0のvectorを返す)
vector<vector<long long>> WarshallFloyd(const Graph &G) {
    long long adj[G.V][G.V];
    for (long long i = 0; i < G.V; i++)
        for (long long j = 0; j < G.V; j++) adj[i][j] = (i == j ? 0 : 1000000000000000007);
    for (long long i = 0; i < G.E; i++) adj[get<0>(G.edges[i])][get<1>(G.edges[i])] = get<2>(G.edges[i]);
    for (long long i = 0; i < G.V; i++)
        for (long long j = 0; j < G.V; j++)
            for (long long k = 0; k < G.V; k++)
                if (adj[j][i] != 1000000000000000007 && adj[i][k] != 1000000000000000007) adj[j][k] = min(adj[j][k], adj[j][i] + adj[i][k]);
    vector<vector<long long>> ans(G.V);
    for (long long i = 0; i < G.V; i++)
        for (long long j = 0; j < G.V; j++)
            for (long long k = 0; k < G.V; k++)
                if (adj[j][i] != 1000000000000000007 && adj[i][k] != 1000000000000000007 && adj[j][k] > adj[j][i] + adj[i][k]) return ans;
    for (long long i = 0; i < G.V; i++)
        for (long long j = 0; j < G.V; j++) ans[i].push_back(adj[i][j]);
    return ans;
}

//ダイクストラ法(到達不可能なら-1を返す)
vector<long long> Dijkstra(const Graph &G, const long long &start) {
    vector<vector<pair<long long, long long>>> adj(G.V);
    for (auto t : G.edges) adj[get<0>(t)].push_back(make_pair(get<1>(t), get<2>(t)));
    vector<long long> dmin(G.V, -1);
    priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> pque;
    pque.push(make_pair(0, start));
    pair<long long, long long> p;
    while (pque.size()) {
        p = pque.top();
        pque.pop();
        if (dmin[p.second] == -1) {
            dmin[p.second] = p.first;
            for (auto x : adj[p.second])
                if (dmin[x.first] == -1) pque.push(make_pair(dmin[p.second] + x.second, x.first));
        }
    }
    return dmin;
}

//ベルマンフォード法(負閉路を含む場合はsize0,到達不可能ならLINFを返す)))
vector<long long> BellmanFord(const Graph &G, const long long &start) {
    vector<long long> dmin(G.V, 1000000000000000007);
    dmin[start] = 0;
    for (long long i = 0; i < G.V - 1; i++)
        for (long long j = 0; j < G.E; j++)
            if (dmin[get<0>(G.edges[j])] != 1000000000000000007) dmin[get<1>(G.edges[j])] = min(dmin[get<1>(G.edges[j])], dmin[get<0>(G.edges[j])] + get<2>(G.edges[j]));
    vector<long long> ans;
    for (long long j = 0; j < G.E; j++)
        if (dmin[get<0>(G.edges[j])] != 1000000000000000007)
            if (dmin[get<1>(G.edges[j])] > dmin[get<0>(G.edges[j])] + get<2>(G.edges[j])) return ans;
    return dmin;
}

//最大フロー
long long max_flow(const Graph &G, const long long &start, const long long &end) {
    long long cf[G.V][G.V], ans = 0;
    for (long long i = 0; i < G.V; i++)
        for (long long j = 0; j < G.V; j++) cf[i][j] = 0;
    for (long long i = 0; i < G.E; i++) cf[get<0>(G.edges[i])][get<1>(G.edges[i])] = get<3>(G.edges[i]);
    queue<long long> que;
    while (1) {
        que.push(start);
        long long dmin[G.V];
        for (long long i = 0; i < G.V; i++) dmin[i] = -1;
        dmin[start] = 0;
        while (que.size()) {
            long long n = que.front();
            for (long long i = 0; i < G.V; i++) {
                if (n != i && cf[n][i] > 0 && dmin[i] == -1) {
                    dmin[i] = n;
                    que.push(i);
                }
            }
            que.pop();
        }
        if (dmin[end] == -1) break;
        vector<long long> way;
        long long n = end;
        while (n != start) {
            way.push_back(n);
            n = dmin[n];
        }
        way.push_back(start);
        long long MIN = 1000000007;
        for (long long i = 0; i < way.size() - 1; i++) MIN = min(MIN, cf[way[i + 1]][way[i]]);
        for (long long i = 0; i < way.size() - 1; i++) {
            cf[way[i]][way[i + 1]] += MIN;
            cf[way[i + 1]][way[i]] -= MIN;
        }
        ans += MIN;
    }
    return ans;
}

//木の直径（辺を双方に貼る必要あり)
long long Diameter(const Graph &G) {
    vector<long long> d = Dijkstra(G, 0);
    long long m = 0, M;
    for (long long i = 0; i < G.V; i++)
        if (m <= d[i]) m = d[i], M = i;
    d = Dijkstra(G, M);
    m = 0;
    for (long long i = 0; i < G.V; i++) m = max(m, d[i]);
    return m;
}

//辞書順最小最短経路を返す
vector<long long> Path(const Graph &G, const long long &start, const long long &goal) {
    vector<vector<pair<long long, long long>>> adj(G.V), adj2(G.V);
    for (auto t : G.edges) adj[get<0>(t)].push_back(make_pair(get<1>(t), get<2>(t)));
    for (auto t : G.edges) adj2[get<1>(t)].push_back(make_pair(get<0>(t), get<2>(t)));
    long long dmin[G.V];
    for (long long i = 0; i < G.V; i++) dmin[i] = -1;
    priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> pque;
    pque.push(make_pair(0, goal));
    pair<long long, long long> p;
    while (pque.size()) {
        p = pque.top();
        pque.pop();
        if (dmin[p.second] == -1) {
            dmin[p.second] = p.first;
            for (auto x : adj[p.second])
                if (dmin[x.first] == -1) pque.push(make_pair(dmin[p.second] + x.second, x.first));
        }
    }
    long long now = start;
    vector<long long> ans(1, now);
    while (now != goal) {
        sort(ALL(adj2[now]));
        for (long long i = 0; i < adj2[now].size(); i++) {
            pair<long long, long long> p = adj2[now][i];
            if (dmin[now] == dmin[p.first] + p.second) {
                ans.push_back(p.first);
                now = p.first;
                break;
            }
        }
    }
    return ans;
}

//ベルマンフォード法 ちょっといじった
vector<long long> BellmanFord(const Graph &G, const long long &start, const long long &goal) {
    vector<long long> dmin(G.V, 1000000000000000007);
    dmin[start] = 0;
    for (long long i = 0; i < 10 * G.V + 10 * G.E - 1; i++)
        for (long long j = 0; j < G.E; j++)
            if (dmin[get<0>(G.edges[j])] != 1000000000000000007) dmin[get<1>(G.edges[j])] = min(dmin[get<1>(G.edges[j])], dmin[get<0>(G.edges[j])] + get<2>(G.edges[j]));
    vector<long long> ans;
    for (long long res = 0; res < 1e5 + G.V + G.E; res++)
        for (long long j = 0; j < G.E; j++)
            if (dmin[get<0>(G.edges[j])] != 1000000000000000007) {
                if (dmin[get<1>(G.edges[j])] > dmin[get<0>(G.edges[j])] + get<2>(G.edges[j]) && get<1>(G.edges[j]) == goal) return ans;
                dmin[get<1>(G.edges[j])] = min(dmin[get<1>(G.edges[j])], dmin[get<0>(G.edges[j])] + get<2>(G.edges[j]));
            }
    return dmin;
}

/* main */

signed main() {
    ll N, M, P;
    cin >> N >> M >> P;
    Graph G(N, M);
    FOR(i, 0, M) {
        ll A, B, C;
        cin >> A >> B >> C;
        A--;
        B--;
        G.add(A, B, P - C);
    }
    auto res = BellmanFord(G, 0, N - 1);
    if (res.size()) {
        if (res[N - 1] == -INF) {
            cout << -1 << endl;
        } else {
            cout << max(-res[N - 1], 0) << endl;
        }
    } else {
        cout << -1 << endl;
    }
}



Measured memory_bytes: 640