#include <bits/stdc++.h>
using namespace std;
int N;
set<pair<int, int> > x, y;
int Work(set<pair<int, int> >& x, set<pair<int, int> >& y) {
  set<pair<int, int> > xx, yy;
  set<pair<int, int> >::iterator x1 = x.begin(), y1 = y.begin();
  set<pair<int, int> >::reverse_iterator x2 = x.rbegin(), y2 = y.rbegin();
  for (int t; *x1 < *x2;) {
    t = x1->first;
    if ((++x1)->first - t > 1) {
      for (pair<int, int> it = *x.begin(); it.first <= t; it = *x.begin()) {
        pair<int, int> jt = make_pair(it.second, it.first);
        xx.insert(it);
        x.erase(it);
        yy.insert(jt);
        y.erase(jt);
      }
      return Work(x, y) + Work(xx, yy);
    }
    t = x2->first;
    if (t - (++x2)->first > 1) {
      for (pair<int, int> it = *x.rbegin(); it.first >= t; it = *x.rbegin()) {
        pair<int, int> jt = make_pair(it.second, it.first);
        x.erase(it);
        xx.insert(it);
        y.erase(jt);
        yy.insert(jt);
      }
      return Work(x, y) + Work(xx, yy);
    }
    t = y1->first;
    if ((++y1)->first - t > 1) {
      for (pair<int, int> it = *y.begin(); it.first <= t; it = *y.begin()) {
        pair<int, int> jt = make_pair(it.second, it.first);
        y.erase(it);
        yy.insert(it);
        x.erase(jt);
        xx.insert(jt);
      }
      return Work(x, y) + Work(xx, yy);
    }
    t = y2->first;
    if (t - (++y2)->first > 1) {
      for (pair<int, int> it = *y.rbegin(); it.first >= t; it = *y.rbegin()) {
        pair<int, int> jt = make_pair(it.second, it.first);
        y.erase(it);
        yy.insert(it);
        x.erase(jt);
        xx.insert(jt);
      }
      return Work(x, y) + Work(xx, yy);
    }
  }
  return 1;
}
int main() {
  for (scanf("%d", &N); N--;) {
    int a, b;
    scanf("%d%d", &a, &b);
    x.insert(make_pair(a, b));
    y.insert(make_pair(b, a));
  }
  printf("%d\n", Work(x, y));
}
