// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define maxx 100010

#define mp make_pair

typedef pair<int,int> ii;

int ans[maxx],visitado[maxx];

vector < ii > ladj[maxx];

map <int, int> dicio;

int n,m,p = 0;

int nos = 0;

vector < int > dist;



void dfs(int x){

	visitado[x] = 1;

	for(auto e: ladj[x]){

		if(visitado[e.second] == 0) dfs(e.second);

	}

}



const int INF = -1e9;

bool spfa(int s) {

    int N = n+1;

    dist.assign(N, INF);

    vector < int > cnt(N, 0);

    vector < bool > inqueue(N, false);

    queue < int > q;

	N = nos;

	

    dist[s] = 0;

    q.push(s);

    inqueue[s] = true;

	while (!q.empty()) {

  

		int atual = q.front();

       	

        q.pop();

    	inqueue[atual] = false;

        for (auto edge : ladj[atual]) {

                int peso = edge.first - p;

		int next = edge.second;



                if (dist[atual] + peso > dist[next] && ans[next] == 1) {

                       dist[next] = dist[atual] + peso;



                       if (!inqueue[next]) {

                              q.push(next);

                              inqueue[next] = true;

                              cnt[next]++;

                    if (cnt[next] > N)

                        return false;  // negative cycle

                }

            }

        }

    }

    return true;

}

vector < int > help; 



int main() {

	cin >> n >> m >> p;

	

	int a,b,w;

	for(int i = 1; i <= m; i++){

		cin >> a >> b >> w;

		ladj[a].push_back(mp(w,b));



	}

	dfs(1);

	bool c = true;

	if(visitado[n] == 1){

		ans[1] = 1;

		nos++;

		for(int i = 2; i <= n;i++){

			for(int j = 1; j <= n+1; j++)visitado[j] = 0;

			dfs(i);

			if(visitado[1] == 1 || visitado[n] == 1){nos++;ans[i] = 1;}



		}

		c = spfa(1);

	}	



	if(c == true) cout << max(0,dist[n]) << endl;

	else cout << -1 << endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.64645575206963x):
#include <bits/stdc++.h>

using namespace std;



const int MAXN = 6000;

vector<pair<long long, pair<int, int>>> adj;

vector<int> adj2[MAXN];

vector<int> adj3[MAXN];

long long dist[MAXN];

int pai[MAXN];

bitset<MAXN> mark, mark2;

int n, m;



void bfs2(int u){

	mark2[u] = 0;

	queue<int> Q;

	Q.push(u);

	while(!Q.empty()){

		int v = Q.front();

		Q.pop();



		for (int k = 0; k < adj3[v].size(); k++){

			int foco = adj3[v][k];

			if (mark2[foco]){

				mark2[foco] = 0;

				//cout << foco << " ---\n";

				Q.push(foco);

			}

		}

	}

}





void bfs(int u){

	mark[u] = 0;

	queue<int> Q;

	Q.push(u);

	while(!Q.empty()){

		int v = Q.front();

		Q.pop();



		for (int k = 0; k < adj2[v].size(); k++){

			int foco = adj2[v][k];

			if (mark[foco]){

				mark[foco] = 0;

				//cout << foco << " ---\n";

				Q.push(foco);

			}

		}

	}

}



int bellmanFord(int s){

	//bellman-ford

	dist[s] = 0;

	for (int i = 1; i < n; i++){

		for (int k = 0; k < adj.size(); k++){

			if (dist[adj[k].second.second] < dist[adj[k].second.first] + adj[k].first){

				dist[adj[k].second.second] = dist[adj[k].second.first] + adj[k].first;

				pai[adj[k].second.second] = adj[k].second.first;

			}

		}

	}

	for (int k = 0; k < adj.size(); k++){

		if (dist[adj[k].second.second] < dist[adj[k].second.first] + adj[k].first && 

			mark[adj[k].second.second] == 0 && mark[adj[k].second.first] == 0 && 

			mark2[adj[k].second.second] == 0 && mark2[adj[k].second.first] == 0){

			//cout << adj[k].second.second << " " << adj[k].second.first << endl;

			return 0;

		}

	}

	return 1;

}



int main(){

	memset(pai, 0, sizeof(pai));

	long long p, w;

	cin >> n >> m >> p;

	for (int i = 0; i <= n; i++)

		dist[i] = -1e9;

	int a, b;

	for (int i = 0; i < m; i++){

		cin >> a >> b >> w;

		a--;

		b--;

		adj.push_back({w-p, {a, b}});

		adj2[b].push_back(a);

		adj3[a].push_back(b);

	}

	mark.set();

	bfs(n-1);

	mark2.set();

	bfs2(0);

	if(!bellmanFord(0)){

		cout << "-1\n";

		return 0;

	}



	if (dist[n-1] < 0) cout << "0\n";

	else cout << dist[n-1] << "\n";



	return 0;

}