def check_and_put(point)
  return 0 if (YS[point[1]] || []).include?(point)
  XS[point[0]] ||= []
  XS[point[0]] << point
  YS[point[1]] ||= []
  YS[point[1]] << point
  1
end

N = gets.to_i
points = N.times.map{ gets.split.map(&:to_i) }
XS = {}
YS = {}
points.each do |point|
  check_and_put(point)
end

score = 0
loop do
  score_incr = 0
  XS.keys.each do |x|
    next if XS[x].size == 1
    XS[x].each do |point|
      y = point[1]
      next if YS[y] == nil || YS[y].size == 1
      YS[y].each do |pnt_y|
        next_x = pnt_y[0]
        XS[x].each do |pnt|
          score_incr += check_and_put([next_x, pnt[1]])
        end
      end
    end
  end
  YS.keys.each do |y|
    next if YS[y].size == 1
    YS[y].each do |point|
      x = point[0]
      next if XS[x] == nil
      XS[x].each do |pnt_x|
        next_y = pnt_x[1]
        YS[y].each do |pnt|
          score_incr += check_and_put([pnt[0], next_y])
        end
      end
    end
  end
  break if score_incr == 0
  score += score_incr
  break
end
puts score
