#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > s, t;
int solve(set<pair<int, int> > &s, set<pair<int, int> > &t) {
  set<pair<int, int> >::iterator it1 = s.begin(), _it1 = t.begin();
  set<pair<int, int> >::reverse_iterator it2 = s.rbegin(), _it2 = t.rbegin();
  while (it1->first < it2->first || _it1->first < _it2->first) {
    int x1 = it1->first, x2 = (++it1)->first;
    if (x2 > x1 + 1) {
      set<pair<int, int> > ret_s, ret_t;
      for (;;) {
        it1 = s.begin();
        if (it1->first == x2) break;
        ret_s.insert(make_pair(it1->first, it1->second));
        ret_t.insert(make_pair(it1->second, it1->first));
        t.erase(make_pair(it1->second, it1->first));
        s.erase(make_pair(it1->first, it1->second));
      }
      return solve(s, t) + solve(ret_s, ret_t);
    }
    x2 = it2->first, x1 = (++it2)->first;
    if (x1 < x2 - 1) {
      set<pair<int, int> > ret_s, ret_t;
      for (;;) {
        it2 = s.rbegin();
        if (it2->first == x1) break;
        ret_s.insert(make_pair(it2->first, it2->second));
        ret_t.insert(make_pair(it2->second, it2->first));
        t.erase(make_pair(it2->second, it2->first));
        s.erase(make_pair(it2->first, it2->second));
      }
      return solve(s, t) + solve(ret_s, ret_t);
    }
    int y1 = _it1->first, y2 = (++_it1)->first;
    if (y2 > y1 + 1) {
      set<pair<int, int> > ret_s, ret_t;
      for (;;) {
        _it1 = t.begin();
        if (_it1->first == y2) break;
        ret_s.insert(make_pair(_it1->second, _it1->first));
        ret_t.insert(make_pair(_it1->first, _it1->second));
        s.erase(make_pair(_it1->second, _it1->first));
        t.erase(make_pair(_it1->first, _it1->second));
      }
      return solve(s, t) + solve(ret_s, ret_t);
    }
    y2 = _it2->first, y1 = (++_it2)->first;
    if (y1 < y2 - 1) {
      set<pair<int, int> > ret_s, ret_t;
      for (;;) {
        _it2 = t.rbegin();
        if (_it2->first == y1) break;
        ret_s.insert(make_pair(_it2->second, _it2->first));
        ret_t.insert(make_pair(_it2->first, _it2->second));
        s.erase(make_pair(_it2->second, _it2->first));
        t.erase(make_pair(_it2->first, _it2->second));
      }
      return solve(s, t) + solve(ret_s, ret_t);
    }
  }
  return 1;
}
int main() {
  int n, x, y;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    s.insert(make_pair(x, y));
    t.insert(make_pair(y, x));
  }
  cout << solve(s, t) << endl;
  return 0;
}
