#include <bits/stdc++.h>
using namespace std;
int n, x, y;
set<pair<int, int> > S, T;
int solve(set<pair<int, int> >& s, set<pair<int, int> >& t) {
  set<pair<int, int> >::iterator it1, it2, it3, it4;
  it1 = s.begin();
  it2 = s.end();
  it2--;
  it3 = t.begin();
  it4 = t.end();
  it4--;
  while (it1->first < it2->first || it3->first < it4->first) {
    int x = it1->first;
    int xx = (++it1)->first;
    if (xx > x + 1) {
      set<pair<int, int> > res_s;
      set<pair<int, int> > res_t;
      while (1) {
        it1 = s.begin();
        if (it1->first == xx) break;
        res_s.insert(make_pair(it1->first, it1->second));
        res_t.insert(make_pair(it1->second, it1->first));
        s.erase(make_pair(it1->first, it1->second));
        t.erase(make_pair(it1->second, it1->first));
      }
      return solve(s, t) + solve(res_s, res_t);
    }
    x = it2->first;
    xx = (--it2)->first;
    if (xx < x - 1) {
      set<pair<int, int> > res_s;
      set<pair<int, int> > res_t;
      while (1) {
        it2 = s.end();
        it2--;
        if (it2->first == xx) break;
        res_s.insert(make_pair(it2->first, it2->second));
        res_t.insert(make_pair(it2->second, it2->first));
        s.erase(make_pair(it2->first, it2->second));
        t.erase(make_pair(it2->second, it2->first));
      }
      return solve(s, t) + solve(res_s, res_t);
    }
    int y = it3->first;
    int yy = (++it3)->first;
    if (yy > y + 1) {
      set<pair<int, int> > res_s;
      set<pair<int, int> > res_t;
      while (1) {
        it3 = t.begin();
        if (it3->first == yy) break;
        res_s.insert(make_pair(it3->second, it3->first));
        res_t.insert(make_pair(it3->first, it3->second));
        s.erase(make_pair(it3->second, it3->first));
        t.erase(make_pair(it3->first, it3->second));
      }
      return solve(s, t) + solve(res_s, res_t);
    }
    y = it4->first;
    yy = (--it4)->first;
    if (yy < y - 1) {
      set<pair<int, int> > res_s;
      set<pair<int, int> > res_t;
      while (1) {
        it4 = t.end();
        it4--;
        if (it4->first == yy) break;
        res_s.insert(make_pair(it4->second, it4->first));
        res_t.insert(make_pair(it4->first, it4->second));
        s.erase(make_pair(it4->second, it4->first));
        t.erase(make_pair(it4->first, it4->second));
      }
      return solve(s, t) + solve(res_s, res_t);
    }
  }
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    S.insert(make_pair(x, y));
    T.insert(make_pair(y, x));
  }
  printf("%d\n", solve(S, T));
  return 0;
}
