#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > X, Y;
int n, ans;
pair<int, int> q[100005];
void solve(set<pair<int, int> > &X, set<pair<int, int> > &Y) {
  set<pair<int, int> > xx, yy;
  auto x1 = X.begin(), ysghysgsygsh = Y.begin();
  auto x2 = X.rbegin(), y2 = Y.rbegin();
  int top = 0;
  for (; *x1 < *x2;) {
    int tmp;
    tmp = x1->first;
    if ((++x1)->first - tmp > 1) {
      for (auto it = X.begin(); *it < *x1; ++it)
        q[++top] = pair<int, int>(it->first, it->second);
      break;
    }
    tmp = x2->first;
    if (tmp - (++x2)->first > 1) {
      for (auto it = X.rbegin(); *it > *x2; ++it)
        q[++top] = pair<int, int>(it->first, it->second);
      break;
    }
    tmp = ysghysgsygsh->first;
    if ((++ysghysgsygsh)->first - tmp > 1) {
      for (auto it = Y.begin(); *it < *ysghysgsygsh; ++it)
        q[++top] = pair<int, int>(it->second, it->first);
      break;
    }
    tmp = y2->first;
    if (tmp - (++y2)->first > 1) {
      for (auto it = Y.rbegin(); *it > *y2; ++it)
        q[++top] = pair<int, int>(it->second, it->first);
      break;
    }
  }
  if (!top) {
    ++ans;
    return;
  }
  for (int i = (int)(1); i <= (int)(top); i++) {
    pair<int, int> it = q[i], jt(it.second, it.first);
    xx.insert(it);
    yy.insert(jt);
    X.erase(it);
    Y.erase(jt);
  }
  solve(X, Y);
  solve(xx, yy);
}
int main() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    X.insert(pair<int, int>(x, y));
    Y.insert(pair<int, int>(y, x));
  }
  solve(X, Y);
  printf("%d\n", ans);
}
