#include <bits/stdc++.h>

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

template <class Weight>
struct edge {
    using weight_type = Weight;

    size_t to;
    Weight m_weight;

    edge(size_t to, Weight weight = 1) : to(to), m_weight(weight) { }

    Weight weight() const {
        return m_weight;
    }
};

template <class Weight>
struct wgraph {
    using edge_type = edge<Weight>;

    const bool is_directed;
    const size_t count_vertices;
    std::vector<edge<Weight>> *edges;

    wgraph(size_t count_vertices, bool is_directed = true) : count_vertices(count_vertices), is_directed(is_directed) {
        edges = new std::vector<edge<Weight>>[count_vertices];
    }

    ~wgraph() {
        delete [] edges;
    }

    void make_edge(size_t u, size_t v, Weight weight) {
        edges[u].push_back(edge<Weight>(v, weight));
        if (!is_directed) {
            edges[v].push_back(edge<Weight>(u, weight));
        }
    }
};

enum value_class_type {
    finite_class,
    pos_inf_class,
    neg_inf_class
};

template <class T>
struct non_standard {
    value_class_type value_class;
    T value;

    non_standard(T value) : value_class(value_class_type::finite_class), value(value) { }

    non_standard(value_class_type value_class, T value) : value_class(value_class), value(value) { }

    bool is_finite() const {
        return value_class == value_class_type::finite_class;
    }

    bool is_pos_inf() const {
        return value_class == value_class_type::pos_inf_class;
    }

    bool is_neg_inf() const {
        return value_class == value_class_type::neg_inf_class;
    }

    static non_standard pos_inf() {
        return non_standard(value_class_type::pos_inf_class, 0);
    }

    static non_standard neg_inf() {
        return non_standard(value_class_type::neg_inf_class, 0);
    }
};

template <class Graph>
std::vector<non_standard<typename Graph::edge_type::weight_type>> bellman_ford(const Graph &g, size_t start) {
    using Edge = typename Graph::edge_type;
    using Weight = typename Edge::weight_type;

    size_t n = g.count_vertices;
    std::vector<non_standard<Weight>> dist(n, non_standard<Weight>::pos_inf());
    dist[start] = non_standard<Weight>(0);
    for (size_t count_loop = 0; ; ++count_loop) {
        bool updated = false;
        for (size_t u = 0; u < n; ++u) {
            if (dist[u].is_finite()) {
                for (const Edge &e: g.edges[u]) {
                    size_t v = e.to;
                    Weight weight = e.weight();
                    if (dist[v].is_pos_inf() || dist[v].is_finite() && dist[v].value > dist[u].value + weight) {
                        if (count_loop < n) {
                            dist[v] = non_standard<Weight>(dist[u].value + weight);
                        } else {
                            dist[v] = non_standard<Weight>::neg_inf();
                        }
                        updated = true;
                    }
                }
            } else if (dist[u].is_neg_inf()) {
                for (const Edge &e: g.edges[u]) {
                    size_t v = e.to;
                    if (!dist[v].is_neg_inf()) {
                        dist[v] = non_standard<Weight>::neg_inf();
                        updated = true;
                    }
                }
            }
        }
        if (!updated) {
            break;
        }
    }
    return dist;
}

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

    ll N, M, P;
    cin >> N >> M >> P;
    wgraph<ll> g(N);
    REP(i, M) {
        int A, B, C;
        cin >> A >> B >> C;
        --A;
        --B;
        g.make_edge(A, B, -C + P);
    }
    auto dist = bellman_ford(g, 0);
    if (dist[N - 1].is_finite()) {
        cout << max(0ll, -dist[N - 1].value) << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}



Measured memory_bytes: 640