import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Edge = Tuple!(int, "from", int, "to", int, "cost");

void main() {
    int N, M, P;
    scan(N, M, P);

    Edge[] es;
    auto adj = new int[][](N, 0);

    foreach (i ; 0 .. M) {
        int ai, bi, ci;
        scan(ai, bi, ci);
        ai--, bi--;
        ci -= P;
        es ~= Edge(ai, bi, -ci);
        adj[bi] ~= ai;
    }

    auto reachable = new bool[](N);
    reachable[N - 1] = true;

    void dfs(int v) {
        reachable[v] = true;
        foreach (u ; adj[v]) {
            if (!reachable[u]) {
                dfs(u);
            }
        }
    }

    dfs(N - 1);

    es = es.filter!(e => reachable[e.to]).array;

    debug {
        writeln(es);
    }

    auto ans = BellmanFord(N, es);

    writeln(ans == -inf6 ? -1 : max(-ans, 0));
}


auto BellmanFord(int N, Edge[] es) {
    auto dist = new long[](N);
    dist[] = inf6;
    dist[0] = 0;

    foreach (i ; 0 .. N - 1) {
        foreach (e ; es) {
            if (dist[e.from] != inf6 && dist[e.from] + e.cost < dist[e.to]) {
                dist[e.to] = dist[e.from] + e.cost;
            }
        }
    }

    foreach (e ; es) {
        if (dist[e.from] != inf6 && dist[e.from] + e.cost < dist[e.to]) {
            return -inf6;
        }
    }

    debug {
        writeln(dist);
    }

    return dist[N - 1];
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}
