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 = [-(10**20)] * 2501
max_coins[1] = 0
coin_n = -999
1.upto(2 * N) do |i|
  update = false
  edges.each do |e|
    if max_coins[e[0]] != -(10**20) && 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

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

puts [max_coins[N], 0].max
