/************************************
 TEMPLATE FOR PROGRAM COMPETITION
 ***********************************/
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

// definition of class edge
class edge{
public:
  long long int from, to, cost;
  
  edge(long long int f, long long int t, long long int c){
    from = f;
    to = t;
    cost = c;
  }
  
  /*bool operator < (const class edge &another) const{
    return cost < another.cost;
  }
  
  bool operator > (const class edge &another) const{
    return cost > another.cost;
    }*/
};

// Bellman_Ford method
// the returned value is  0 if the loop converged
//                        1 if the loop did no converge
int Bellman_Ford(std::vector<edge> &G, std::vector<int> &reached, long long int E, long long int V, std::vector<long long int> &distance, long long int start);


int main(){
  // the number of edge and vertex
  long long int E, V, P;
  
  //read E and V from input
  scanf("%lld%lld%lld", &V, &E, &P);
  
  // graph
  std::vector<edge> G;
  long long int f_tmp, t_tmp, c_tmp;
  
  // push all edges to the graph
  for(int i = 0; i < E; i++){
    scanf("%lld%lld%lld", &f_tmp, &t_tmp, &c_tmp);
    // G is undirected
    G.push_back(edge(f_tmp-1, t_tmp-1, P-c_tmp));
  }
  
  // prepare Bellman_Ford
  std::vector<int> reached(V);
  for(long long int i = 0; i < V; i++){
    reached[i] = 0;
  }
  std::vector<long long int> distance(V);
  for(long long int i = 0; i < V; i++){
    distance[i] = 0;
  }
  reached[0] = 1;
  
  // Bellman_Ford
  int flag = Bellman_Ford(G, reached, E, V, distance, 0);
  
  if(flag == 1){
    std::cerr << "Bellman Ford did not converge" << std::endl;
    std::cout << -1 << std::endl;
  }
  else{
    if(distance[V-1] < 0){
      std::cout << -distance[V-1] << std::endl;
    }
    else{
      std::cout << 0 << std::endl;
    }
  }
  // test code
  /*
  // print the problem settig
  std::cerr << "V: " << V << std::endl << "E: " << E << std::endl << "G:" << std::endl;
  for(int i = 0; i < 2*E; i++){
    std::cerr << G[i].from << " " << G[i].to << " " << G[i].cost << std::endl;
  }std::cerr << std::endl;
  
  // prepare vectors
  std::vector<int> reached(V);
  for(long long int i = 0; i < V; i++){
    reached[i] = 0;
  }
  std::vector<long long int> distance(V);
  for(long long int i = 0; i < V; i++){
    distance[i] = 0;
  }
  
  reached[0] = 1;
  Bellman_Ford(G, reached, 2*E, V, distance, 0);
  
  for(int i = 0; i < V; i++){
    std::cout << distance[i] << " ";
  }std::cout << std::endl << std::endl;*/
  
  return 0;
  
}

int Bellman_Ford(std::vector<edge> &G, std::vector<int> &reached, long long int E, long long int V, std::vector<long long int> &distance, long long int start){
  int update = 1;
  int update2 = 0;
  for(long long int i = 0; i < 2*V; i++){
    update = 0;
    
    for(long long int e = 0; e < E; e++){
      if(reached[G[e].from] && !(reached[G[e].to])){
        distance[G[e].to] = distance[G[e].from] + G[e].cost;
        reached[G[e].to] = 1;
        update = 1;
      }
      else if(reached[G[e].from] && reached[G[e].to] && (distance[G[e].to] > distance[G[e].from] + G[e].cost)){
        distance[G[e].to] = distance[G[e].from] + G[e].cost;
        update = 1;
        if(i > V && G[e].to == V-1){
          update2 = 1;
          break;
        }
      }
    }
    
    // if there is no update, end the loop
    if(update == 0){
      break;
    }
  }
  
  /*if(update == 0){ // if the loop did not converge
    return 0;
  }
  else{ // if(update == 1), // if the loop converged
    return 1;
  }*/
  return update2;
  
}


Measured memory_bytes: 512