import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M, P = in.next().toInt
  val graph = Array.fill[List[(Int, Int)]](N+1)(Nil) // to, cost
  val graphRev = Array.fill[List[(Int, Int)]](N+1)(Nil) // to, cost
  for (i <- 0 until M) {
    val A, B, C = in.next().toInt
    graph(A) = (B, C) :: graph(A)
    graphRev(B) = (A, C) :: graphRev(B)
  }

  //
  val dpFor = new Array[Boolean](N+1)
  val q = Queue[Int](1)
  while (!q.isEmpty) {
    val now = q.dequeue()
    if (!dpFor(now)) {
      dpFor(now) = true
      for ((node, _) <- graph(now)) {
        q.enqueue(node)
      }
    }
  }

  val dpRev = new Array[Boolean](N+1)
  q.enqueue(N)
  while (!q.isEmpty) {
    val now = q.dequeue()
    if (!dpRev(now)) {
      dpRev(now) = true
      for ((node, _) <- graphRev(now)) {
        q.enqueue(node)
      }
    }
  }


  val dp = new Array[Boolean](N+1)
  for (i <- 1 to N)
    dp(i) = dpFor(i) && dpRev(i)

  var edges = List[Edge]()
  for (i <- 1 to N if dp(i)) {
    for ((node, cost) <- graph(i) if dp(node)) {
      edges = Edge(i, node, -(cost - P)) :: edges
    }
  }

  val bf = new BellmanFord(N+1, edges.length, edges.toArray)

  if (bf.findNegativeLoop)
    println(-1)
  else {
    bf.shortestPath(1)
    println(Math.max(0, -bf.d(N)))
  }
}

// O(|V|*|E|)
case class Edge(from: Int, to: Int, cost: Long)

// V: 頂点数, E: 辺数
// 0-based index
class BellmanFord(V: Int, E: Int, es: Array[Edge]) {

  val d = new Array[Long](V) // 最短距離

  private[this] val INF = Long.MaxValue

  // s番目の頂点から各頂点への最短距離を求める
  // 負のループがあると止まらない
  def shortestPath(s: Int): Unit = {
    for (i <- 0 until V)
      d(i) = INF

    d(s) = 0
    breakable {
      while (true) {
        var update = false
        for(i <- 0 until E) {
          val e = es(i)
          if (d(e.from) != INF && d(e.to) > d(e.from) + e.cost) {
            d(e.to) = d(e.from) + e.cost
            update = true
          }
        }

        if (!update)
          break
      }
    }
  }

  // true なら負の閉路が存在する
  def findNegativeLoop(): Boolean = {
    for (i <- 0 until V)
      d(i) = 0

    for (i <- 0 until V) {
      for (j <- 0 until E) {
        val e = es(j)
        if (d(e.to) > d(e.from) + e.cost) {
          d(e.to) = d(e.from) + e.cost

          // n 回目にも更新があるなら負の閉路が存在する
          if (i == V - 1)
            return true
        }
      }
    }

    false
  }

}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
