#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
int x[110000], y[110000], n;
set<pair<int, int> > sx, sy;
int work(set<pair<int, int> > &sx, set<pair<int, int> > &sy) {
  if (sx.size() == 1) return 1;
  set<pair<int, int> >::iterator it1, it2, it3, it4;
  it1 = sx.begin();
  it2 = sx.end();
  it2--;
  it3 = sy.begin();
  it4 = sy.end();
  it4--;
  set<pair<int, int> > dx, dy;
  auto renew = [&](bool flag, set<pair<int, int> >::iterator i) {
    int t = i->second;
    pair<int, int> tmp = make_pair((i->first == x[t] ? y[t] : x[t]), t);
    if (!flag) {
      dx.insert(*i);
      dy.insert(tmp);
      sy.erase(tmp);
      sx.erase(i);
    } else {
      dy.insert(*i);
      dx.insert(tmp);
      sx.erase(tmp);
      sy.erase(i);
    }
  };
  for (;;) {
    int tmp;
    tmp = it1->first;
    if ((++it1)->first > tmp + 1) {
      for (auto i = sx.begin(); i != it1;) {
        auto I = i++;
        renew(0, I);
      }
      return work(dx, dy) + work(sx, sy);
    }
    tmp = it3->first;
    if ((++it3)->first > tmp + 1) {
      for (auto i = sy.begin(); i != it3;) {
        auto I = i++;
        renew(1, I);
      }
      return work(dx, dy) + work(sx, sy);
    }
    if (it1 == it2) break;
    tmp = it2->first;
    if ((--it2)->first < tmp - 1) {
      for (auto i = ++it2; i != sx.end();) {
        auto I = i++;
        renew(0, I);
      }
      return work(dx, dy) + work(sx, sy);
    }
    tmp = it4->first;
    if ((--it4)->first < tmp - 1) {
      for (auto i = ++it4; i != sy.end();) {
        auto I = i++;
        renew(1, I);
      }
      return work(dx, dy) + work(sx, sy);
    }
    if (it1 == it2) break;
  }
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &x[i], &y[i]);
  for (int i = 1; i <= n; ++i)
    sx.insert(make_pair(x[i], i)), sy.insert(make_pair(y[i], i));
  printf("%d\n", work(sx, sy));
}
