require 'set'

n, m, point = gets.strip.split.map(&:to_i)
abc = readlines.map {|line| line.strip.split.map(&:to_i) }

graph = Array.new(n+1) { [] }
reverse_graph = Array.new(n+1) { [] }
edges = []

abc.each do |a, b, c|
  edges << [a, b, (c-point)*-1]
  graph[a] << [b, (c-point)*-1]
  reverse_graph[b] << [a, (c-point)*-1]
end

def reachable(graph, s)
  visit = Set.new
  visit.add(s)
  q=[s]
  until q.empty?
    u=q.shift
    graph[u].each do |n, _|
      next if visit.include?(n)
      visit.add(n)
      q.push(n)
    end
  end
  visit
end

reachable_from_s = reachable(graph, 1)
reachable_to_g = reachable(reverse_graph, n)
#retrenched_nodes = reachable_from_s & reachable_to_g

retrenched_nodes = Set.new
(1..n).each {|node| retrenched_nodes.add(node) if reachable_to_g.include?(node) && reachable_from_s.include?(node) }

edges = edges.select {|from, to,  _| retrenched_nodes.include?(from) && retrenched_nodes.include?(to) }

INF = Float::INFINITY
dist = Array.new(n+1, INF)
dist[1]=0
c=0

loop do
  updated = false
  edges.each do |from, to, cost|
    if dist[from] != INF && dist[to] > dist[from] + cost
      dist[to] = dist[from] + cost
      updated=true
    end
  end
  break unless updated
  c+=1
  if c==retrenched_nodes.size
    p -1
    exit
  end
end

p [-dist[n], 0].max
