import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.meta;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;



long solve(ref int N, ref int M, ref int P, ref int[] A, ref int[] B, ref int[] C){
  auto prev = new int[2501];
  auto cost = new long[2501];
  auto used = new bool[2501];

  foreach (i; 0 .. 2501) {
    cost[i] = long.max;
  }

  cost[1] = 0;
  used[1] = true;

  bool infloop = true;
  foreach (_; 0 .. N) {
    bool update = false;
    foreach (i; 0 .. M) {
      auto a = A[i];
      auto b = B[i];
      auto c = P - C[i];
      if (used[a] && cost[b] > cost[a] + c) {
        update = true;
        cost[b] = cost[a] + c;
        prev[b] = a;
        used[b] = true;
      }
    }
    if (!update) {
      infloop = false;
      break;
    }
  }
  
  if (infloop) {
    auto v = N;
    auto g = 0;
    foreach (_; 0 .. (2 * N)) {
      v = prev[v];
      if (v == 1)
        g++;
    }
    if (g != 1) {
      return -1;
    }
  }

  if (-cost[N] <= 0)
    return 0;
  
  return -cost[N];
}

void main(){
    int N;
    readf(" %d", &N);
    int M;
    readf(" %d", &M);
    int P;
    readf(" %d", &P);
    int[] A = new int[](cast(uint) M);
    int[] B = new int[](cast(uint) M);
    int[] C = new int[](cast(uint) M);
    for(int i = 0; i < M; i++){
        readf(" %d", &A[i]);
        readf(" %d", &B[i]);
        readf(" %d", &C[i]);
    }
    auto ans = solve(N, M, P, A, B, C);
    writeln(ans);
}
