N, M, P = gets.chomp.split.map(&:to_i)

edges = []
M.times { edges.push(gets.chomp.split.map(&:to_i)) }
edges.map! { |a, b, c| [a, b, c - P] }

max_coins = [-1] * 2501
max_coins[1] = 0
coin_N = -1
1.upto(2 * N) do |i|
  update = false
  edges.each do |e|
    if max_coins[e[0]] != -1 && max_coins[e[1]] <= max_coins[e[0]] + e[2]
      max_coins[e[1]] = max_coins[e[0]] + e[2]
      update = true
    end
  end

  coin_N = max_coins[N] if i == N - 1

  if i > N && coin_N != max_coins[N] # have loop
    puts "-1"
    exit
  end
  break if update == false
end

puts [max_coins[N], 0].max
