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 cost = new long[](N + 1);
    auto used = new bool[](N + 1);

    fill(cost, long.max);
    cost[1] = 0;
    used[1] = true;

    foreach (t; 0 .. (2 * N)) {
        foreach (a, b, c; zip(A, B, C.map!(x => P - x))) {
            if (used[a] && cost[b] > cost[a] + c) {
                cost[b] = cost[a] + c;
                used[b] = true;
                if (b == N && t >= N)
                    return -1;
            }
        }
    }

    return max(0, -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);
}
