#n = gets.chomp.to_i
n, m, P = gets.chomp.split().map(&:to_i)
edges = Array.new(m)
m.times do |i|
  a,b,c=gets.chomp.split.map(&:to_i)
  edges[i] = a,b,P-c
end
#p edges

# v_num :: Voltex数
# edges :: [[from, to, cost], [from, to, cost], ...]
# s :: start
def shortest_path(v_num, edges, s)
  d = Array.new(v_num, Float::INFINITY)
  d[s - 1] = 0

  count = 0
  dlast = nil

  while true
    update = false

    edges.each do |from, to, cost|
      dfcost = d[from-1] + cost
      if dfcost != Float::INFINITY && d[to - 1] > dfcost
        d[to - 1] = dfcost
        update = true
      end
    end
    break if !update

    count += 1
    if count == v_num
      puts -1
      exit
      dlast = d.last
    elsif count == v_num * 2
      if dlast == d.last
        return d
      else
        puts -1
        exit
      end
    end
  end
  d
end

paths = shortest_path(n, edges, 1)
puts [paths.last * -1, 0].max
