#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
  int x, y;
  node(int X = 0, int Y = 0) { x = X, y = Y; }
};
struct cmpx {
  bool operator()(const node &a, const node &b) {
    return a.x == b.x ? a.y < b.y : a.x < b.x;
  }
};
struct cmpy {
  bool operator()(const node &a, const node &b) {
    return a.y == b.y ? a.x < b.x : a.y < b.y;
  }
};
bool cmp(const node &a, const node &b) {
  return (a.x ^ b.x) ? a.x < b.x : a.y < b.y;
}
int solve(set<node, cmpx> &xx, set<node, cmpy> &yy) {
  if (xx.size() == 1) return 1;
  set<node, cmpx> xx1;
  set<node, cmpy> sy1;
  set<node, cmpx>::iterator ix1;
  set<node, cmpx>::reverse_iterator ix2;
  set<node, cmpy>::iterator iy1;
  set<node, cmpy>::reverse_iterator iy2;
  ix1 = xx.begin();
  ix2 = xx.rbegin();
  iy1 = yy.begin();
  iy2 = yy.rbegin();
  int t;
  do {
    t = ix1->x;
    ix1++;
    if (ix1->x - t > 1) {
      while (xx.begin()->x <= t) {
        node a = *xx.begin();
        xx1.insert(a);
        sy1.insert(a);
        yy.erase(a);
        xx.erase(a);
      }
      return solve(xx, yy) + solve(xx1, sy1);
    }
    t = ix2->x;
    ix2++;
    if (t - ix2->x > 1) {
      while (xx.rbegin()->x >= t) {
        node a = *xx.rbegin();
        xx1.insert(a);
        sy1.insert(a);
        yy.erase(a);
        xx.erase(a);
      }
      return solve(xx, yy) + solve(xx1, sy1);
    }
    t = iy1->y;
    iy1++;
    if (iy1->y - t > 1) {
      while (yy.begin()->y <= t) {
        node a = *yy.begin();
        xx1.insert(a);
        sy1.insert(a);
        xx.erase(a);
        yy.erase(a);
      }
      return solve(xx, yy) + solve(xx1, sy1);
    }
    t = iy2->y;
    iy2++;
    if (t - iy2->y > 1) {
      while (yy.rbegin()->y >= t) {
        node a = *yy.rbegin();
        xx1.insert(a);
        sy1.insert(a);
        xx.erase(a);
        yy.erase(a);
      }
      return solve(xx, yy) + solve(xx1, sy1);
    }
  } while (cmp(*ix1, *ix2));
  return 1;
}
set<node, cmpx> px;
set<node, cmpy> py;
int main() {
  scanf("%d", &n);
  for (int i = 1, x, y; i <= n; i++)
    scanf("%d%d", &x, &y), px.insert(node(x, y)), py.insert(node(x, y));
  printf("%d\n", solve(px, py));
}
