import java.util.*

fun main(args: Array<String>) {
    val (N, M, P) = readLine()!!.split(" ").map{it.toInt()}

    val g = Graph(N + 1, 0L, 1e15.toLong()) { a, b -> a + b }

    for (i in 1..M) {
        val (A, B, C) = readLine()!!.split(" ").map{it.toInt()}

        g.edges[A].add(Edge(A, B, P.toLong() - C))
    }

    val (dist, prev, hasNegativeLoop) = bellmanFord(g, 1, N)

    println(if (hasNegativeLoop) -1 else Math.max(0, -dist[N]))
}

data class Edge<T: Comparable<T>>(val from: Int, val to: Int, val weight: T): Comparable<Edge<T>> {
    constructor(from: Long, to: Long, weight: T) : this(from.toInt(), to.toInt(), weight)

    override fun compareTo(other: Edge<T>) = weight.compareTo(other.weight)
}

class Graph<T: Comparable<T>>(val n: Int, val zero: T, val inf: T, val plus: (T, T) -> T) {
    val edges = Array(n) { ArrayList<Edge<T>>() }
}

inline fun <reified T: Comparable<T>>bellmanFord(g: Graph<T>, s: Int): Triple<Array<T>, Array<Int>, Boolean> {
    val N = g.n
    val dist = Array(N) { g.inf }
    val prev = Array(N) {-1}
    var hasNegativeLoop = false

    dist[s] = g.zero

    for (k in 1 .. N + 1) {
        for (v in 0 until N) {
            for (e in g.edges[v]) {
                if (dist[e.from] != g.inf && dist[e.to] > g.plus(dist[e.from], e.weight)) {
                    dist[e.to] = g.plus(dist[e.from], e.weight)
                    prev[e.to] = e.from
                    hasNegativeLoop = k == N + 1
                }
            }
        }
    }

    return Triple(dist, prev, hasNegativeLoop)
}

fun <T : Comparable<T>>listVertices(g: Graph<T>, s: Int, t: Int): Array<Boolean> {
    fun listReachable(g: Graph<T>, s: Int): Array<Boolean> {
        val reachable = Array(g.n) { false }
        val Q = ArrayDeque<Int>()

        reachable[s] = true
        Q.addLast(s)

        while (Q.isNotEmpty()) {
            val v = Q.pollFirst()

            for (e in g.edges[v]) {
                if (reachable[e.to]) continue
                reachable[e.to] = true
                Q.addLast(e.to)
            }
        }

        return reachable
    }

    val rG = Graph(g.n, g.zero, g.inf, g.plus)
    for (v in 0 until g.n) {
        for (e in g.edges[v]) {
            rG.edges[e.to].add(Edge(e.to, e.from, e.weight))
        }
    }

    val reachable = listReachable(g, s)
    val reverseReachable = listReachable(rG, t)

    return reachable.indices.map { reachable[it] && reverseReachable[it] }.toTypedArray()
}

inline fun <reified T : Comparable<T>>bellmanFord(g: Graph<T>, s: Int, t: Int): Triple<Array<T>, Array<Int>, Boolean> {
    val vs = listVertices(g, s, t)

    val refinedGraph = Graph(g.n, g.zero, g.inf, g.plus)

    for (v in 0 until g.n) {
        for (e in g.edges[v]) {
            if (vs[e.from] && vs[e.to]) {
                refinedGraph.edges[e.from].add(e)
            }
        }
    }

    return bellmanFord(refinedGraph, s)
}
