#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 20;
inline bool shittoc(set<pair<int, int> > &a, int x) {
  set<pair<int, int> >::iterator l = a.lower_bound(make_pair(x, -1e9 - 1));
  set<pair<int, int> >::iterator r = a.lower_bound(make_pair(x + 1, -1e9 - 1));
  return (l == a.end() || l == r) && (r != a.end() && l != a.begin());
}
inline int solve(set<pair<int, int> > &a, set<pair<int, int> > &b) {
  set<pair<int, int> >::iterator cl = a.begin(), cr = a.end(), ru = b.begin(),
                                 rd = b.end();
  cr--, rd--;
  for (int i = 0; i * 2 < (int)a.size(); i++) {
    if (shittoc(a, (cl->first) + 1)) {
      set<pair<int, int> > tmpa, tmpb;
      while ((*a.begin()).first <= (*cl).first) {
        pair<int, int> tmp = *a.begin();
        a.erase(tmp);
        tmpa.insert(tmp);
        swap(tmp.first, tmp.second);
        b.erase(tmp);
        tmpb.insert(tmp);
      }
      return solve(tmpa, tmpb) + solve(a, b);
    }
    if (shittoc(a, (cr->first) + 1)) {
      set<pair<int, int> > tmpa, tmpb;
      while ((*a.rbegin()).first > (*cr).first) {
        pair<int, int> tmp = *a.rbegin();
        a.erase(tmp);
        tmpa.insert(tmp);
        swap(tmp.first, tmp.second);
        b.erase(tmp);
        tmpb.insert(tmp);
      }
      return solve(tmpa, tmpb) + solve(a, b);
    }
    if (shittoc(b, (ru->first) + 1)) {
      set<pair<int, int> > tmpa, tmpb;
      while ((*b.begin()).first <= (*ru).first) {
        pair<int, int> tmp = *b.begin();
        b.erase(tmp);
        tmpb.insert(tmp);
        swap(tmp.first, tmp.second);
        a.erase(tmp);
        tmpa.insert(tmp);
      }
      return solve(tmpa, tmpb) + solve(a, b);
    }
    if (shittoc(b, (rd->first) + 1)) {
      set<pair<int, int> > tmpa, tmpb;
      while ((*b.rbegin()).first > (*rd).first) {
        pair<int, int> tmp = *b.rbegin();
        b.erase(tmp);
        tmpb.insert(tmp);
        swap(tmp.first, tmp.second);
        a.erase(tmp);
        tmpa.insert(tmp);
      }
      return solve(tmpa, tmpb) + solve(a, b);
    }
    cl++;
    cr--;
    ru++;
    rd--;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  set<pair<int, int> > a, b;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a.insert({x, y});
    b.insert({y, x});
  }
  cout << solve(a, b) << endl;
}
