#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > p;
set<pair<int, int> > h;
set<pair<int, int> > v;
int cut();
int cut(set<pair<int, int> >::iterator s, set<pair<int, int> >::iterator e) {
  int c = 0;
  vector<int> all;
  while (s != e) {
    all.push_back(s->second);
    ++s;
  }
  for (int &x : all) {
    h.erase(pair<int, int>(p[x].first, x));
    v.erase(pair<int, int>(p[x].second, x));
  }
  c += cut();
  h.clear();
  v.clear();
  for (int &x : all) {
    h.insert(pair<int, int>(p[x].first, x));
    v.insert(pair<int, int>(p[x].second, x));
  }
  c += cut();
  return c;
}
int cut() {
  set<pair<int, int> >::iterator xs = h.begin();
  set<pair<int, int> >::iterator ys = v.begin();
  set<pair<int, int> >::iterator xe = h.end();
  set<pair<int, int> >::iterator ye = v.end();
  --xe;
  --ye;
  for (int i = 0; i < (int)h.size() / 2; ++i) {
    set<pair<int, int> >::iterator nxs = xs;
    ++nxs;
    if (xs->first + 1 < nxs->first) {
      return cut(h.begin(), nxs);
    }
    ++xs;
    set<pair<int, int> >::iterator nxe = xe;
    --xe;
    if (xe->first + 1 < nxe->first) {
      return cut(nxe, h.end());
    }
    set<pair<int, int> >::iterator nys = ys;
    ++nys;
    if (ys->first + 1 < nys->first) {
      return cut(v.begin(), nys);
    }
    ++ys;
    set<pair<int, int> >::iterator nye = ye;
    --ye;
    if (ye->first + 1 < nye->first) {
      return cut(nye, v.end());
    }
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    p.push_back(pair<int, int>(x, y));
    h.insert(pair<int, int>(x, i));
    v.insert(pair<int, int>(y, i));
  }
  cout << cut() << endl;
  return 0;
}
