require "set"

n, m, p = gets.split.map(&:to_i)
g0 = Hash.new {|hash, k| hash[k] = {} }
reverse_g = Hash.new {|hash, k| hash[k] = []}
m.times do
  a, b, c = gets.split.map(&:to_i)
  g0[a - 1][b - 1] = -(c - p)
  reverse_g[b - 1] << a - 1
end

preserve = Set[0]
try = ->(s, pool = []) {
  return pool if pool.include?(s) || s.zero?
  reverse_g[s].each {|node| preserve.merge(try.(node, pool + [s]))}
}
try.(n - 1)

g = Hash.new {|hash, k| hash[k] = {} }
g0.each do |k0, v0|
  v0.each do |k, v|
    g[k0][k] = v if preserve.include?(k)
  end
end

shortest = Hash.new(Float::INFINITY)
shortest[0] = 0
(n + 1).times do
  g.map {|x| [x[0], x[1].keys]}.each do |k, v|
    v.each do |x|
      if (a = shortest[k] + g[k][x]) < shortest[x]
        shortest[x] = a
      end
    end
  end
end
score = -shortest[n - 1]
score = 0 if score < 0

g.each do |u, v0|
  v0.each_key do |v|
    score = -1 if shortest[u] + g[u][v] < shortest[v]
  end
end

puts score