#n = gets.chomp.to_i
de = false
require 'set'
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 if de

edge_hash = {}
edges.each do |a,b,c|
  edge_hash[b] ||= []
  edge_hash[b].push a
end
q = [n]
visited = Set.new([n])
until q.empty?
  cur = q.shift # bfs
  next unless edge_hash.has_key? cur
  edge_hash[cur].each do |v|
    next if visited.include?(v)
    visited.add v
    q.push v
  end
end
p visited if de

edges.select!{|a,b,c| visited.include?(a) && visited.include?(b)}
p edges if de

# 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|
      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 * 2
      if dlast == d.last
        return d
      else
        puts -1
        exit
      end
    end
  end
  d
end

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