#include <bits/stdc++.h>
using namespace std;
int n, x, y;
set<pair<int, int> > qx, qy;
pair<int, int> rev(pair<int, int> a) {
  swap(a.first, a.second);
  return a;
}
int rec(set<pair<int, int> > &a, set<pair<int, int> > &b) {
  auto al = a.begin();
  auto ar = a.rbegin();
  auto bl = b.begin();
  auto br = b.rbegin();
  int lx = al->first, ly = bl->first, rx = ar->first, ry = br->first;
  set<pair<int, int> > nxta, nxtb;
  while (al != a.end()) {
    if (al->first - lx > 1) {
      while (a.begin()->first <= lx) {
        pair<int, int> to = *a.begin();
        a.erase(to);
        b.erase(rev(to));
        nxta.insert(to);
        nxtb.insert(rev(to));
      }
      return rec(nxta, nxtb) + rec(a, b);
    }
    if (bl->first - ly > 1) {
      while (b.begin()->first <= ly) {
        pair<int, int> to = *b.begin();
        b.erase(to);
        a.erase(rev(to));
        nxtb.insert(to);
        nxta.insert(rev(to));
      }
      return rec(nxta, nxtb) + rec(a, b);
    }
    while (rx - ar->first > 1) {
      while (a.rbegin()->first >= rx) {
        pair<int, int> to = *a.rbegin();
        a.erase(to);
        b.erase(rev(to));
        nxta.insert(to);
        nxtb.insert(rev(to));
      }
      return rec(a, b) + rec(nxta, nxtb);
    }
    while (ry - br->first > 1) {
      while (b.rbegin()->first >= ry) {
        pair<int, int> to = *b.rbegin();
        b.erase(to);
        a.erase(rev(to));
        nxtb.insert(to);
        nxta.insert(rev(to));
      }
      return rec(a, b) + rec(nxta, nxtb);
    }
    if (*al > *ar) {
      break;
    }
    lx = al->first, ly = bl->first, rx = ar->first, ry = br->first;
    al++, bl++, ar++, br++;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    qx.insert(make_pair(x, y));
    qy.insert(make_pair(y, x));
  }
  cout << rec(qx, qy);
}
