#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > byX, byY;
void move(set<pair<int, int> > &byX, set<pair<int, int> > &byY,
          set<pair<int, int> > &byX2, set<pair<int, int> > &byY2,
          pair<int, int> obj) {
  byX.erase(obj);
  byY.erase({obj.second, obj.first});
  byX2.insert(obj);
  byY2.insert({obj.second, obj.first});
}
int gao(set<pair<int, int> > &byX, set<pair<int, int> > &byY) {
  if (byX.size() == 1) return 1;
  auto x_forward = byX.begin();
  auto x_backward = byX.rbegin();
  auto y_forward = byY.begin();
  auto y_backward = byY.rbegin();
  set<pair<int, int> > byX2, byY2;
  int pre;
  do {
    pre = x_forward->first;
    x_forward++;
    if (x_forward->first - pre > 1) {
      while (byX.begin()->first <= pre) {
        move(byX, byY, byX2, byY2, *byX.begin());
      }
      return gao(byX, byY) + gao(byX2, byY2);
    }
    pre = x_backward->first;
    x_backward++;
    if (pre - x_backward->first > 1) {
      while (byX.rbegin()->first >= pre) {
        move(byX, byY, byX2, byY2, *byX.rbegin());
      }
      return gao(byX, byY) + gao(byX2, byY2);
    }
    pre = y_forward->first;
    y_forward++;
    if (y_forward->first - pre > 1) {
      while (byY.begin()->first <= pre) {
        move(byY, byX, byY2, byX2, *byY.begin());
      }
      return gao(byX, byY) + gao(byX2, byY2);
    }
    pre = y_backward->first;
    y_backward++;
    if (pre - y_backward->first > 1) {
      while (byY.rbegin()->first >= pre) {
        move(byY, byX, byY2, byX2, *byY.rbegin());
      }
      return gao(byX, byY) + gao(byX2, byY2);
    }
  } while (*x_forward < *x_backward);
  return 1;
}
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &x, &y);
    byX.insert({x, y});
    byY.insert({y, x});
  }
  cout << gao(byX, byY) << '\n';
  return 0;
}
