n, m ,p = gets.split.map(&:to_i)
g = []
to = Array.new(n + 1) {[]}
ot = Array.new(n + 1) {[]}
m.times do
  a, b, c = gets.split.map(&:to_i)
  g << [a, b, -(c - p)]
  to[a] << b
  ot[b] << a
end

toflag = [0] * (n + 1)
toflag[1] = 1
iki = ->(v) {
  to[v].each do |u|
    if toflag[u].zero?
      toflag[u] = 1
      iki.(v)
    end
  end
}
iki.(1)

otflag = [0] * (n + 1)
otflag[n] = 1
kaeri = ->(v) {
  ot[v].each do |u|
    if otflag[u].zero?
      otflag[u] = 1
      kaeri.(v)
    end
  end
}
kaeri.(n)

cand = toflag.zip(otflag).map {|a, b| a * b}

bf = ->{
  inf = Float::INFINITY
  d = Array.new(n + 1, inf)
  d[1] = 0
  update = true
  (n + 1).times do |i|
    update = false
    g.each do |v, u, cost|
      next if cand[v] != 1 || cand[u] != 1
      if d[v] != inf && d[u] > (a = d[v] + cost)
        d[u] = a
        update = true
      end
    end
    break unless update
    return inf if i == n
  end
  -d[n]
}
ans = bf.()

ans = (ans == Float::INFINITY) ? -1 : [ans, 0].max
puts ans