#n = gets.chomp.to_i
n, m, P = gets.chomp.split().map(&:to_i)
edges = readlines.map{|m| m.chomp.split.map(&:to_i)}

edges.map!{|a,b,c| [a,b,(c-P)*-1]}
#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 |e|
      from, to, cost = e

      if d[from - 1] != Float::INFINITY && d[to - 1] > (d[from - 1] + cost)
        d[to - 1] = (d[from - 1] + cost)
        update = true
      end
    end
    break if !update

    count += 1
    if count == v_num
      dlast = d.last
    elsif count == v_num * 3
      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
