#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct point {
  int x, y;
};
struct cmpx {
  bool operator()(const point &p1, const point &p2) {
    return p1.x < p2.x || (p1.x == p2.x && p1.y < p2.y);
  }
};
struct cmpy {
  bool operator()(const point &p1, const point &p2) {
    return p1.y < p2.y || (p1.y == p2.y && p1.x < p2.x);
  }
};
int n, ans = 0;
set<point, cmpx> allx;
set<point, cmpy> ally;
void init() {
  scanf("%d", &n);
  for (int i = 1, x = 0, y = 0; i <= n; ++i) {
    scanf("%d%d", &x, &y);
    allx.insert((point){x, y});
    ally.insert((point){x, y});
  }
}
int tot = 0;
void work(set<point, cmpx> &xl, set<point, cmpy> &yl) {
  set<point, cmpx> newx;
  set<point, cmpy> newy;
  set<point, cmpx>::iterator sx = xl.begin(), ex = --xl.end();
  set<point, cmpy>::iterator sy = yl.begin(), ey = --yl.end();
  int flag = 0;
  while (sx != ex || sy != ey) {
    if (flag == 3) {
      flag = 0;
      if (sx == ex) continue;
      set<point, cmpx>::iterator last = sx++;
      if (last->x < sx->x - 1) {
        for (set<point, cmpx>::iterator it = xl.begin(); it != sx; ++it) {
          point tmp = *it;
          newx.insert(tmp);
          newy.insert(tmp);
          yl.erase(tmp);
        }
        xl.erase(xl.begin(), sx);
        work(newx, newy);
        work(xl, yl);
        return;
      }
    } else if (flag == 0) {
      flag = 1;
      if (sx == ex) continue;
      set<point, cmpx>::iterator next = ex--;
      if (next->x > ex->x + 1) {
        for (set<point, cmpx>::iterator it = next; it != xl.end(); ++it) {
          point tmp = *it;
          newx.insert(tmp);
          newy.insert(tmp);
          yl.erase(tmp);
        }
        xl.erase(next, xl.end());
        work(newx, newy);
        work(xl, yl);
        return;
      }
    } else if (flag == 1) {
      flag = 2;
      if (sy == ey) continue;
      set<point, cmpy>::iterator last = sy++;
      if (last->y < sy->y - 1) {
        for (set<point, cmpy>::iterator it = yl.begin(); it != sy; ++it) {
          point tmp = *it;
          newx.insert(tmp);
          newy.insert(tmp);
          xl.erase(tmp);
        }
        yl.erase(yl.begin(), sy);
        work(newx, newy);
        work(xl, yl);
        return;
      }
    } else if (flag == 2) {
      flag = 3;
      if (sy == ey) continue;
      set<point, cmpy>::iterator next = ey--;
      if (next->y > ey->y + 1) {
        for (set<point, cmpy>::iterator it = next; it != yl.end(); ++it) {
          point tmp = *it;
          newx.insert(tmp);
          newy.insert(tmp);
          xl.erase(tmp);
        }
        yl.erase(next, yl.end());
        work(newx, newy);
        work(xl, yl);
        return;
      }
    }
  }
  ++ans;
}
int main() {
  init();
  work(allx, ally);
  printf("%d\n", ans);
  return 0;
}
