#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e16;
const double EPS=1e-8;
const ll mod = 1000000007;
#include <limits>
#include <vector>
#include <queue>
class Vertex;
class Edge{
public:
	friend class Vertex;
	friend class Graph;
	Vertex* from;
	Vertex* to;
	int64_t cost;
public:
	Edge(Vertex* from,Vertex* to,int64_t cost=0){
		this->from=from;
		this->to=to;
		this->cost=cost;
	}

};
struct Dijkstra{
	int64_t d;
	Vertex* parent;
	bool searched;
};

class Vertex{
	friend class Graph;

public:
	Dijkstra dijk_data;
	std::vector<Edge*> departure;
	std::vector<Edge*> arrival;

	int32_t id;
	bool forward_reachable=false;
	bool backward_reachable=false;
	bool count_finish=false;
	void add_edge(Edge* d){
		departure.push_back(d);
		d->to->arrival.push_back(d);
	}
	void initialize_Dijkstra(){
		dijk_data.d=INF;
		dijk_data.parent=NULL;
		dijk_data.searched=false;
	}
	int32_t count_union(Edge* e1,Edge* e2){
		int32_t retval=1;
		count_finish=true;
		for(auto i1=departure.begin();i1!=departure.end();i1++){
			Edge *temp=(*i1);
			if(temp==e1||temp==e2||temp->to->count_finish){
				continue;
			}
			retval+=temp->to->count_union(e1,e2);
		}
		return retval;
	}
};
class dijkstra_calc{
public:
	int64_t current_cost;
	Vertex* from;
	Vertex* to;
	dijkstra_calc(const int64_t cost, Vertex* c1,Vertex* c2):current_cost(cost),from(c1),to(c2){

	}
};
bool operator<(const dijkstra_calc& a,const dijkstra_calc& b){
	return a.current_cost<b.current_cost;
}
bool operator>(const dijkstra_calc& a,const dijkstra_calc& b){
	return a.current_cost>b.current_cost;
}


class Graph{
private:
	std::vector<Vertex*> v;
	std::vector<Edge*> e;
	int64_t **WF;
	void initialize_Dijkstra(){
		for(auto i=v.begin();i!=v.end();i++){
			Vertex *temp=(*i);
			temp->initialize_Dijkstra();
		}
	}
	static void dijkstra(Vertex* source,Vertex* goal=NULL){
		std::priority_queue<dijkstra_calc,std::vector<dijkstra_calc>,std::greater<dijkstra_calc> > queue;
		queue.push(dijkstra_calc(0,NULL,source));
		while(true){
			const dijkstra_calc temp=queue.top();
			queue.pop();
			if(!(temp.to->dijk_data.searched)){
				temp.to->dijk_data.searched=true;
				temp.to->dijk_data.parent=temp.from;
				temp.to->dijk_data.d=temp.current_cost;

				for(auto i=temp.to->departure.begin();i!=temp.to->departure.end();i++){
					const Edge *j=(*i);
					if(!j->to->dijk_data.searched){
						dijkstra_calc a(temp.current_cost+(j->cost),j->from,j->to);
						queue.push(a);
					}
				}
				if(temp.to==goal){
					return;
				}
			}
			if(queue.empty()){
				return;
			}
		}
	}
	bool Bellman_Ford(Vertex* source){//use after initialize_Dijkstra
		source->dijk_data.d=0;
		ll repeat = v.size();
		bool updated = false;
		for(ll i1=0;i1<repeat;i1++){
			updated = false;
			for(auto i2=e.begin();i2!=e.end();i2++){
				Edge* edge_temp = (*i2);
				if((edge_temp->from->forward_reachable)&&(edge_temp->to->backward_reachable)&&((edge_temp->from->dijk_data.d+edge_temp->cost) < (edge_temp->to->dijk_data.d))){
					updated = true;
					edge_temp->to->dijk_data.d=edge_temp->from->dijk_data.d+edge_temp->cost;
				}
			}
		}
		return updated;
	}
public:
	static const int64_t INF=1000000000000000;
	Graph(int32_t num_v){
		v.reserve(num_v);
		for(int32_t i1=0;i1<num_v;i1++){
			Vertex* temp=new Vertex();
			temp->id=i1;
			v.push_back(temp);
		}
		WF=new int64_t*[num_v];
		for(int64_t i1=0;i1<num_v;i1++){
			WF[i1]=new int64_t[num_v];
		}
	}
	void add_edge(int32_t from,int32_t to,ll cost=0){
		Edge *temp=new Edge(v[from],v[to],cost);
		e.push_back(temp);
		v[from]->add_edge(temp);
	}
	void dijkstra(int32_t start){
		initialize_Dijkstra();
		dijkstra(v[start]);
	}
	void dijkstra(int32_t start,int32_t goal){
		initialize_Dijkstra();
		dijkstra(v[start],v[goal]);
	}
	bool Bellman_Ford(int32_t start){
		initialize_Dijkstra();
		return Bellman_Ford(v[start]);
	}
	int64_t** WarshallFloid(){
		for(int64_t i1=0;i1<v.size();i1++){
			for(int64_t i2=0;i2<v.size();i2++){
				WF[i1][i2]=INF;
			}
		}
		for(int64_t i1=0;i1<v.size();i1++){
			for(auto i2=v[i1]->departure.begin();i2!=v[i1]->departure.end();i2++){
				Edge *temp=(*i2);
				if(WF[i1][temp->to->id]>temp->cost){
					WF[i1][temp->to->id]=temp->cost;
				}
			}
			WF[i1][i1]=0;
		}
		for(int64_t i1=0;i1<v.size();i1++){
			for(int64_t i2=0;i2<v.size();i2++){
				for(int64_t i3=0;i3<v.size();i3++){
					WF[i2][i3]=min(WF[i2][i3],WF[i2][i1]+WF[i1][i3]);
				}
			}
		}
		return WF;
	}
	Vertex* getVertex(int place) const{
		return v[place];
	}
	bool isBridge(Edge* e1,Edge* e2){
		for(auto i1=v.begin();i1!=v.end();i1++){
			Vertex* temp=(*i1);
			temp->count_finish=false;
		}
		int32_t r=v[0]->count_union(e1,e2);
		return v.size()!=r;
	}
	vector<Edge*> getEdge(){
		return e;
	}
	virtual ~Graph(){
		for(auto i=v.begin();i!=v.end();i++){
			delete *i;
		}
		for(auto i=e.begin();i!=e.end();i++){
			delete *i;
		}
		for(int64_t i1=0;i1<v.size();i1++){
			delete[] WF[i1];
		}
		delete[] WF;
	}
};

void forward_reachable(Vertex* ve){
	ve->forward_reachable=true;
	vector<Edge*> edges = ve->departure;
	for(auto i1=edges.begin();i1!=edges.end();i1++){
		Edge *temp = *i1;
		if(!(temp->to->forward_reachable)){
			forward_reachable(temp->to);
		}
	}
}
void backward_reachable(Vertex* ve){
	ve->backward_reachable=true;
	vector<Edge*> edges = ve->arrival;
	for(auto i1=edges.begin();i1!=edges.end();i1++){
		Edge *temp = *i1;
		if(!(temp->from->backward_reachable)){
			backward_reachable(temp->from);
		}
	}

}
int main(){
	ll n,m,p;
	cin>>n>>m>>p;
	Graph gr(n);
	for(ll i1=0;i1<m;i1++){
		ll a,b,c;
		cin>>a>>b>>c;
		gr.add_edge(a-1,b-1,-(c-p));
	}
	forward_reachable(gr.getVertex(0));
	backward_reachable(gr.getVertex(n-1));

	bool impossible = gr.Bellman_Ford(0);
	if(impossible){
		cout<<-1<<endl;
	}else{
		cout<<max<ll>(0,-1*(gr.getVertex(n-1)->dijk_data.d))<<endl;
	}
}


Measured memory_bytes: 11008