#n = gets.chomp.to_i
@d = 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 @d

def visit_check(edge_map, start)
  q = [start]
  visited = Set.new([start])
  until q.empty?
    cur = q.shift # bfs
    next if edge_map[cur].empty?
    edge_map[cur].each do |v|
      next if visited.include?(v)
      visited.add v
      q.push v
    end
  end
  p visited if @d
  visited
end
edge_map = Array.new(n+1){Set.new}
edge_map2 = Array.new(n+1){Set.new}
edges.each do |a,b,c|
  edge_map[a].add b
  edge_map2[b].add a
end
visited = visit_check(edge_map, 1)
edges.select!{|a,b,c| visited.include?(a) && visited.include?(b)}
p ['edges', edges] if @d

visited = visit_check(edge_map2, n)
edges.select!{|a,b,c| visited.include?(a) && visited.include?(b)}
p ['edges', edges] if @d

# 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

  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
      puts -1
      exit
    end
  end
  d
end

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