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

abc = abc.map {|a, b, c| [a, b, -1*(c-tax)] }

# graph及びreverse_graphの構築

graph = Array.new(n+1) { [] }
r_graph = Array.new(n+1) { [] }
abc.each do |a, b, c|
  graph[a] << [b,c]
  r_graph[b] << [a,c]
end

def reachable(g, s)
  result = []
  q = [s]
  until q.empty?
    current = q.shift
    result << current
    g[current].each do |to, cost|
      next if result.include?(to)
      q << to
      result << to
    end
  end
  result
end

# 到達可能なノードの洗い出し
retrenched_nodes = reachable(graph, 1) & reachable(r_graph, n)
retrenched_roads = abc.select {|a, b, _| retrenched_nodes.include?(a) && retrenched_nodes.include?(b) }

INF = 10**12
dist = Array.new(n+1, INF)
dist[1]=0
updated = false

# 到達可能ノードに対するBF
# BFの中でdistを更新していく
retrenched_nodes.each do
  updated = false
  retrenched_roads.each do |a, b, c|
    if dist[a] != INF && dist[b] > dist[a] + c
      dist[b] = dist[a] + c
      updated = true
    end
  end

  break unless updated
end

#p dist

if updated
  p -1
  exit
end

# 求まった最初コストに対してマイナスをかけて0と比較、大きい方を提出

#p retrenched_nodes
#p dist
p [-1*dist[n], 0].max


