class Node(val id: Long) {
    private val edges = mutableListOf<Edge>()
    val nextNodes = mutableListOf<Node>()
    var distance: Long = Long.MAX_VALUE
    var predecessor: Node? = null
    fun addEdge(edge: Edge, node: Node) {
        edges.add(edge)
        nextNodes.add(node)
    }
}

class Edge(val from: Long, val to: Long, val cost: Long) {

}

class Graph(val nodes: Array<Node>, val edges: Array<Edge>) {
    private val nodesMap = mutableMapOf<Long, Node>()

    init {
        for (node in nodes) {
            nodesMap[node.id] = node
        }
        for (edge in edges) {
            nodesMap[edge.from]?.addEdge(edge, nodesMap[edge.to]!!)
        }
    }

    fun node(id: Long): Node = nodesMap[id]!!

    fun solveBellmanFord(startId: Long) {
//        init
        nodesMap[startId]!!.distance = 0
//        relaxing
        for (i in 1 until nodes.size) {
            for (edge in edges) {
                val u = nodesMap[edge.from]!!
                val v = nodesMap[edge.to]!!
                if (u.distance == Long.MAX_VALUE) continue

                if (v.distance > u.distance + edge.cost) {
                    v.distance = u.distance + edge.cost
                    v.predecessor = u
                }
            }
        }
//        check negative circle
        for (edge in edges) {
            if (nodesMap[edge.from]!!.distance == Long.MAX_VALUE) continue

            val u = nodesMap[edge.from]!!
            val v = nodesMap[edge.to]!!
            if (v.distance > u.distance + edge.cost) {
//                閉路検出：ゴールへ行けるか判定
                val visited = mutableSetOf<Node>().run {
                    addAll(u.nextNodes)
                    this
                }
                while (true) {
                    val visitedTmp = visited.toSet()
                    for (node in visited) {
                        visited.addAll(node.nextNodes)
                    }
                    if (visited.size == visitedTmp.size) break
                }
                if (!visited.contains(nodes.last())) continue

                throw RuntimeException("negative circle detect!")
            }
        }
    }
}

fun main(args: Array<String>) {
    val (N, M, P) = readLine()!!.split(' ').map(String::toLong)
    val nodes = Array(N.toInt()) { Node(it.toLong() + 1) }
    val edges = Array(M.toInt()) {
        val (a, b, c) = readLine()!!.split(' ').map(String::toLong)
        Edge(a, b, -(c - P))
    }
    val graph = Graph(nodes, edges)
    try {
        graph.solveBellmanFord(1L)
        val ans = -graph.node(N).distance
        println(if (ans >= 0) ans else 0)
    } catch (e: RuntimeException) {
//        println(e)
        println(-1)
    }
}
