#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 2505;
const int MAX_M = 5005;
const ll INF = 1e15;
ll d[MAX_N];
ll N,M;
bool update[MAX_N];

struct edge
{
	int from,to,cost;
};

edge es[MAX_M];

int main()
{
	ll P;
	cin >> N >> M >> P;
	rep(i,M)
	{
		int a,b;
		ll c;
		cin >> a >> b >> c;
		a--; b--;
		c -= P;
		c *= -1;
		es[i].from = a;
		es[i].to = b;
		es[i].cost = c;
	}

	rep(i,N)
	{
		d[i] = INF;
	}
	d[0] = 0;
	rep(j,N)
	{
		rep(i,M)
		{
			edge e = es[i];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost)
			{
				d[e.to] = d[e.from] + e.cost;
			}
		}
	}

	rep(j,N)
	{
		rep(i,M)
		{
			edge e = es[i];
			if (update[e.from] || (d[e.from] != INF && d[e.to] > d[e.from] + e.cost))
			{
				update[e.to] = true;
			}
		}
	}

	//cout << dN << " " << d[N-1] << endl;
	if (update[N-1]) cout << "-1" << endl;
	else cout << max(ll(0),-1*d[N-1]) << endl;
	return 0;
}