/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Gosu_Hiroo
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define TR(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define IN(c, x) ((c).find(x) != (c).end())   //O(log n)
#define IN_L(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define PLL pair<ll,ll>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define FOR(i, _begin, _end) for (__typeof(_end) end = _end, begin = _begin,  i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define REP(i, end) for (__typeof(end) i = 0, _len = (end); i < (_len); i += 1)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define MOD(x, m) ((((x) % (m)) + (m)) % (m))
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define READ ({int t;cin >> t;t;})
#define EB emplace_back
#define fcout cout << fixed << setprecision(12)
#define fcerr cerr << fixed << setprecision(12)
#define print(x) cout << (x) << endl

#ifdef DEBUG
#define ERR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); _err(cerr,_it, args); }
#define DBG(x) cerr << #x << " is " << x << endl;
#else
#define DBG(x) {};
#define ERR(args...) {};
#endif
void _err(std::ostream& cerr,istream_iterator<string> it) {cerr << endl;}
template<typename T, typename... Args>
void _err(std::ostream& cerr, istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << "  ";
    _err(cerr,++it, args...);
}

const double pi = 2 * acos(.0);
const int inf = 0x3f3f3f3f;
const ll mod = (ll) (1e9) + 7;
//const ll mod = (ll) 998244353 ;
const double eps = 1e-10;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}

template <typename T>
ostream& operator << (ostream& os, const vector<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

template <typename T>
ostream& operator << (ostream& os, const set<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

template <typename T>
ostream& operator << (ostream& os, const deque<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

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; }

//#define int ll

ll ans = 0;
int N,M,P;
bool connected[4000];
vector<int> g_r[4000];
struct Edge {
    int src, dest, weight;
};
struct Graph {
    // V-> Number of vertices, E-> Number of edges
    int V, E;

    // graph is represented as an array of edges.
    struct Edge* edge;
};

// Creates a graph with V vertices and E edges
struct Graph* createGraph(int V, int E)
{
    struct Graph* graph = new Graph;
    graph->V = V;
    graph->E = E;
    graph->edge = new Edge[graph->E];
    return graph;
}

bool isNegCycleBellmanFord(struct Graph* graph,
                           int src)
{
    int V = graph->V;
    int E = graph->E;
    int dist[V];

    // Step 1: Initialize distances from src
    // to all other vertices as INFINITE
    for (int i = 0; i < V; i++)
        dist[i] = INT_MAX;
    dist[src] = 0;



    for (int i = 1; i <= V - 1; i++) {
        for (int j = 0; j < E; j++) {
            int u = graph->edge[j].src;
            int v = graph->edge[j].dest;
            int weight = graph->edge[j].weight;
            if (dist[u] != INT_MAX && dist[u] + weight < dist[v])
                dist[v] = dist[u] + weight;
        }
    }

    for (int i = 0; i < E; i++) {
        int u = graph->edge[i].src;
        int v = graph->edge[i].dest;
        int weight = graph->edge[i].weight;
        if (dist[u] != INT_MAX && connected[v] &&dist[u] + weight < dist[v])
            return true;
    }
    ans = dist[N-1];
    return false;
}

void dfs(int s){
    if(connected[s])return;
    connected[s] = 1;
    for(auto adj : g_r[s])if(!connected[adj])dfs(adj);
}
class ECoinsRespawn {
public:

void solve(std::istream& cin, std::ostream& cout, std::ostream& cerr) {
    cin >> N >> M >> P;
    Graph* g = createGraph(N,M);
    Fill(connected, 0);
    REP(m,M){
        int a,b,c;
        cin >> a >> b >> c;
        a--, b--;
        g->edge[m].src = a;
        g->edge[m].dest = b;
            g->edge[m].weight = P-c;
        g_r[b].EB(a);
    }
    dfs(N-1);
    if(isNegCycleBellmanFord(g,0))cout << "-1" << endl;
    else if(ans >= 0)cout << 0 << endl;
    else cout << -ans << endl;


}


};


#undef int
int main() {

	ECoinsRespawn solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
    std::ostringstream err;
	in.tie(0); ios::sync_with_stdio(0);
//	solver.solve(in, out);
    solver.solve(in, out,err);
	return 0;
}


Measured memory_bytes: 640