require 'set'

n, m, point = gets.strip.split.map(&:to_i)
N=n
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

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

def bellman_ford(edge_list, s, max_count)
  d = Array.new(N+1, INF)
  d[s] = 0
  c = 0
  loop do
    is_update = false
    edge_list.each do |(u, v, c)|
      if d[u] != INF && d[u] + c < d[v]
        d[v] = d[u] + c
        is_update = true
      end
    end
    return d if !is_update
    c += 1
    return nil if c == max_count
  end
end

ans = bellman_ford(edges, 1, retrenched_nodes.size)
if ans.nil?
  p -1
  exit
end

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