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

immutable long INF = 1L << 40;

void main() {
    Scanner scanner = new Scanner(stdin);
    scope(exit) assert(!scanner.hasNext);

    int N, M;
    long P;
    scanner.read(N, M, P);
    auto G = new Tuple!(int, long)[][](N);
    foreach (_; 0..M) {
        int u, v;
        long c;
        scanner.read(u, v, c);
        u--;
        v--;
        G[u] ~= tuple(v, c);
    }

    auto dist = new long[](N);
    dist[]= INF;
    dist[0] = 0;

    foreach (i; 0..N) {
        foreach (v; 0..N) {
            foreach (to; G[v]) {
                int u = to[0];
                long c = to[1];
                if (dist[v] != INF && dist[u] > dist[v] + c) {
                    dist[u] = dist[v] + c;
                    if (i == N - 1) {
                        dist[u] = -INF;
                    }
                }
            }
        }
    }

    if (dist[N-1] <= -INF || dist[N-1] == INF) {
        writeln(-1);
    } else {
        writeln(max(0L, -dist[N-1]));
    }
}


class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    private File f;

    this(File f) {
        this.f = f;
    }
    private char[512] lineBuf;
    private char[] line;
    private bool succW() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (!line.empty && line.front.isWhite) {
            line.popFront;
        }
        return !line.empty;
    }
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            line = lineBuf[];
            f.readln(line);
            if (!line.length) return false;
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {


                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else static if (isStaticArray!T) {
                foreach (i; 0..T.length) {
                    assert(succW());
                    x[i] = line.parse!E;
                }
            } else {
                StackPayload!E buf;
                while (succW()) {
                    buf ~= line.parse!E;
                }
                x = buf.data;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }


    int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }

    void read(Args...)(auto ref Args args) {
        import std.exception : enforce;
        static if (args.length != 0) {
            enforce(readSingle(args[0]));
            read(args[1..$]);
        }
    }

    bool hasNext() {
        return succ();
    }
}
