#include <bits/stdc++.h>
using namespace std;
void slashTheUniverse(set<pair<int, int> >& xs, set<pair<int, int> >& ys,
                      set<pair<int, int> >& newxs, set<pair<int, int> >& newys,
                      pair<int, int> pof, bool left) {
  auto it = (left ? xs.begin() : xs.end());
  if (!left) it--;
  while (*it != pof) {
    pair<int, int> tmp = *it;
    xs.erase(it);
    newxs.insert(tmp);
    swap(tmp.first, tmp.second);
    ys.erase(tmp);
    newys.insert(tmp);
    it = (left ? xs.begin() : xs.end());
    if (!left) it--;
  }
}
int countUniverses(set<pair<int, int> >& xs, set<pair<int, int> >& ys) {
  if (xs.empty()) return 0;
  auto xl = xs.begin(), yl = ys.begin();
  auto xr = xs.rbegin(), yr = ys.rbegin();
  set<pair<int, int> > newxs, newys;
  while (*xl < *xr) {
    if (xl->first + 1 < (++xl)->first)
      slashTheUniverse(xs, ys, newxs, newys, *xl, true);
    else if (yl->first + 1 < (++yl)->first)
      slashTheUniverse(ys, xs, newys, newxs, *yl, true);
    else if (xr->first - 1 > (++xr)->first)
      slashTheUniverse(xs, ys, newxs, newys, *xr, false);
    else if (yr->first - 1 > (++yr)->first)
      slashTheUniverse(ys, xs, newys, newxs, *yr, false);
    else
      continue;
    return countUniverses(xs, ys) + countUniverses(newxs, newys);
  }
  return 1;
}
int main() {
  int n;
  scanf("%d", &n);
  set<pair<int, int> > xs, ys;
  for (int i = 0, q, w; i < n; i++) {
    scanf("%d%d", &q, &w);
    xs.insert(make_pair(q, w));
    ys.insert(make_pair(w, q));
  }
  printf("%d\n", countUniverses(xs, ys));
  return 0;
}
