N, M, P = gets.split.map(&:to_i)
Vertex, Edge = Struct.new(:distance), Struct.new(:from, :to, :weight)
vertices = Array.new(N.next) {|i| Vertex.new(i == 1 ? 0 : -Float::INFINITY)}
edges = $<.read.split(?\n).map do |x|
  a, b, c = x.split.map(&:to_i)
  from, to = vertices.values_at(a, b)
  weight = c - P
  Edge.new(from, to, weight)
end

N.times do
  edges.each do |edge|
    next if edge.to.distance < edge.from.distance + edge.weight
    edge.to.distance = edge.from.distance + edge.weight
  end
end

(puts 0; exit) if vertices[N].distance.negative?
(puts '-1'; exit) if edges.any? {|edge| edge.from.distance + edge.weight > edge.to.distance}
puts vertices[N].distance
