class Edge
  attr_reader :from, :to, :cost

  def initialize(from, to, cost)
    @from = from
    @to = to
    @cost = cost
  end
end

INF = 10010010001

def coins_respawn(n, edges)
  d = Array.new(n, INF)
  d[0] = 0
  n.times do
    edges.each do |e|
      if d[e.from] != INF && d[e.to] > d[e.from] + e.cost
        d[e.to] = d[e.from] + e.cost
      end
    end
  end

  cost = d[n - 1]

  n.times do
    edges.each do |e|
      if d[e.from] != INF && d[e.to] > d[e.from] + e.cost
        d[e.to] = d[e.from] + e.cost
      end
    end
  end

  return -1 if cost != d[n - 1]
  cost = -1 * cost
  cost > 0 ? cost : 0
end

n, m, p = gets.split.map(&:to_i)
edges = []
m.times do
  param = gets.split.map(&:to_i)
  edges << Edge.new(param[0] - 1, param[1] - 1, (param[2] - p) * -1)
end

puts coins_respawn(n, edges)