#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 1000 + 10;
const int maxn5 = 2 * 1000 * 100 + 10;
const int maxnJ = 1000 + 10;
const long long mod = 1000 * 1000 * 1000 + 7;
const long long inf = 1LL * 2 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 10;
set<pair<int, int>> av[2];
int cnt = 0, ind = 0, x[2][maxn5];
vector<int> ex[maxn5];
void solve() {
  if (av[1].size() == 1) {
    av[1].clear();
    av[0].clear();
    cnt++;
    return;
  }
  auto l1 = av[0].begin(), r1 = av[0].end();
  r1--;
  auto l2 = av[1].begin(), r2 = av[1].end();
  r2--;
  int ty = 0, turn;
  auto imp = l1;
  int b = 0;
  while ((*l1) < (*r1)) {
    l1++, r1--;
    auto ll1 = l1, rr1 = r1;
    l1--, r1++;
    if (ll1->first - l1->first > 1) imp = ll1, ty = 1, turn = 0;
    if (r1->first - rr1->first > 1) imp = rr1, ty = 2, turn = 0;
    l1++, r1--;
    if (ty != 0) break;
    l2++, r2--;
    auto ll2 = l2, rr2 = r2;
    l2--, r2++;
    if (ll2->first - l2->first > 1) imp = ll2, ty = 1, turn = 1;
    if (r2->first - rr2->first > 1) imp = rr2, ty = 2, turn = 1;
    l2++, r2--;
    if (ty != 0) break;
    b++;
  }
  if (ty == 0) {
    av[0].clear();
    av[1].clear();
    cnt++;
    return;
  }
  int a = ind++;
  if (ty == 1) {
    auto it = av[turn].begin();
    while (it != imp) {
      auto tmp = it;
      it++;
      int i = tmp->second;
      av[turn ^ 1].erase({x[turn ^ 1][i], i});
      av[turn].erase(tmp);
      ex[a].push_back(i);
    }
  } else {
    auto it = av[turn].end();
    it--;
    while (it != imp) {
      auto tmp = it;
      it--;
      int i = tmp->second;
      av[turn ^ 1].erase({x[turn ^ 1][i], i});
      av[turn].erase(tmp);
      ex[a].push_back(i);
    }
  }
  solve();
  for (auto i : ex[a])
    av[turn].insert({x[turn][i], i}), av[turn ^ 1].insert({x[turn ^ 1][i], i});
  ex[a].clear();
  solve();
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[0][i] >> x[1][i];
    av[0].insert({x[0][i], i});
    av[1].insert({x[1][i], i});
  }
  solve();
  cout << cnt << endl;
  return 0;
}
