#include <bits/stdc++.h>
using namespace std;
const int Max_N(100050);
struct nodex {
  nodex(int _x = 0, int _y = 0) : x(_x), y(_y) {}
  int x, y;
  inline bool operator<(const nodex &b) const {
    return x == b.x ? y < b.y : x < b.x;
  }
};
nodex Vx[Max_N];
struct nodey {
  nodey(int _x = 0, int _y = 0) : x(_x), y(_y) {}
  int x, y;
  inline bool operator<(const nodey &b) const {
    return y == b.y ? x < b.x : y < b.y;
  }
};
nodey Vy[Max_N];
int N, X[Max_N], Y[Max_N];
int conquery(set<nodex> &Sx, set<nodey> &Sy) {
  if (Sx.size() <= 0) return Sx.size();
  set<nodex> Tx;
  set<nodey> Ty;
  set<nodex>::iterator ix_1, ix, jx, jx_1;
  set<nodey>::iterator iy_1, iy, jy, jy_1;
  ++(ix_1 = ix = Sx.begin()), ++(iy_1 = iy = Sy.begin());
  --(jx_1 = --(jx = Sx.end())), --(jy_1 = --(jy = Sy.end()));
  for (int l = 0, r = Sx.size() + 1, Cnt = Sx.size(); ix_1 != Sx.end();
       ++ix, ++ix_1, ++iy, ++iy_1, --jx, --jx_1, --jy, --jy_1) {
    ++l, Vx[l] = *ix, Vy[l] = *iy;
    --r, Vx[r] = *jx, Vy[r] = *jy;
    if (ix_1->x - ix->x > 1) {
      for (int i = 1; i <= l; ++i)
        Sx.erase(Vx[i]), Sy.erase(nodey(Vx[i].x, Vx[i].y)), Tx.insert(Vx[i]),
            Ty.insert(nodey(Vx[i].x, Vx[i].y));
      return conquery(Tx, Ty) + conquery(Sx, Sy);
    }
    if (jx->x - jx_1->x > 1) {
      for (int i = r; i <= Cnt; ++i)
        Sx.erase(Vx[i]), Sy.erase(nodey(Vx[i].x, Vx[i].y)), Tx.insert(Vx[i]),
            Ty.insert(nodey(Vx[i].x, Vx[i].y));
      return conquery(Sx, Sy) + conquery(Tx, Ty);
    }
    if (iy_1->y - iy->y > 1) {
      for (int i = 1; i <= l; ++i)
        Sy.erase(Vy[i]), Sx.erase(nodex(Vy[i].x, Vy[i].y)), Ty.insert(Vy[i]),
            Tx.insert(nodex(Vy[i].x, Vy[i].y));
      return conquery(Tx, Ty) + conquery(Sx, Sy);
    }
    if (jy->y - jy_1->y > 1) {
      for (int i = r; i <= Cnt; ++i)
        Sy.erase(Vy[i]), Sx.erase(nodex(Vy[i].x, Vy[i].y)), Ty.insert(Vy[i]),
            Tx.insert(nodex(Vy[i].x, Vy[i].y));
      return conquery(Sx, Sy) + conquery(Tx, Ty);
    }
  }
  return 1;
}
int main() {
  set<nodex> Sx;
  set<nodey> Sy;
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i)
    scanf("%d%d", X + i, Y + i), Sx.insert(nodex(X[i], Y[i])),
        Sy.insert(nodey(X[i], Y[i]));
  printf("%d", conquery(Sx, Sy));
  return 0;
}
