N, M, P = gets.split.map(&:to_i)
E = Hash.new { |h, k| h[k] = Hash.new }
R = Hash.new { |h, k| h[k] = Hash.new }

edges = []

M.times do
  a, b, c = gets.split.map(&:to_i)

  E[a][b] = c - P
  R[b][a] = c - P
  edges << [a, b, c]
end

visited = Hash.new

queue = []
queue.push(N)

until queue.empty?
  v = queue.shift

  next if visited[v]
  visited[v] = true

  R[v].each do |u, _|
    queue << u
  end
end

cost = Hash.new(-Float::INFINITY)
cost[1] = 0
loop_cnt = 0

edges.select! { |_, b, _| visited[b] }

loop do
  updated = false

  edges.each do |from, to, c|
    nc = cost[from] + c - P

    if cost[from] != -Float::INFINITY && cost[to] < nc
      cost[to] = nc
      updated = true
    end
  end

  break unless updated

  loop_cnt += 1

  break if loop_cnt >= N
end

if loop_cnt >= N
  puts -1
elsif cost[N] == -Float::INFINITY
  puts -1
else
  puts [cost[N], 0].max
end
