#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
  point(int a, int b) { x = a, y = b; }
  bool operator<(const point pt) const {
    if (x == pt.x) {
      return y < pt.y;
    }
    return x < pt.x;
  }
  point rev() const { return point(y, x); }
};
int solve(set<point>& s, set<point>& t) {
  set<point> a, b;
  auto L1 = s.begin(), R1 = --s.end();
  auto L2 = t.begin(), R2 = --t.end();
  while (*L1 < *R1) {
    auto X1 = L1, Y1 = R1;
    auto X2 = L2, Y2 = R2;
    ++X1, --Y1, ++X2, --Y2;
    if (L1->x < X1->x - 1) {
      for (auto it = s.begin(); it != X1; it++) {
        a.insert(*it);
        b.insert(it->rev());
      }
    } else if (L2->x < X2->x - 1) {
      for (auto it = t.begin(); it != X2; it++) {
        a.insert(it->rev());
        b.insert(*it);
      }
    } else if (R1->x > Y1->x + 1) {
      for (auto it = R1; it != s.end(); it++) {
        a.insert(*it);
        b.insert(it->rev());
      }
    } else if (R2->x > Y2->x + 1) {
      for (auto it = R2; it != t.end(); it++) {
        a.insert(it->rev());
        b.insert(*it);
      }
    } else {
      ++L1, --R1, ++L2, --R2;
      continue;
    }
    for (auto p : a) {
      s.erase(p);
      t.erase(p.rev());
    }
    return solve(s, t) + solve(a, b);
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  set<point> s, t;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    s.insert(point(x, y));
    t.insert(point(y, x));
  }
  cout << solve(s, t) << '\n';
  return 0;
}
