#include <bits/stdc++.h>
using namespace std;
pair<int, int> rev(pair<int, int> a) {
  swap(a.first, a.second);
  return a;
}
int solve(set<pair<int, int> >& s, set<pair<int, int> >& t) {
  set<pair<int, int> > a, b;
  for (auto L1 = s.begin(), R1 = --s.end(), L2 = t.begin(), R2 = --t.end();
       *L1 < *R1; L1++, R1--, L2++, R2--) {
    auto nxt1 = L1, prev1 = R1, nxt2 = L2, prev2 = R2;
    nxt1++, prev1--, nxt2++, prev2--;
    if (L1->first < nxt1->first - 1)
      for (auto p : s) {
        a.insert(p);
        b.insert(rev(p));
        if (p == *L1) break;
      }
    else if (R1->first > prev1->first + 1)
      while (R1 != s.end()) {
        a.insert(*R1);
        b.insert(rev(*R1));
        R1++;
      }
    else if (L2->first < nxt2->first - 1)
      for (auto p : t) {
        b.insert(p);
        a.insert(rev(p));
        if (p == *L2) break;
      }
    else if (R2->first > prev2->first + 1)
      while (R2 != t.end()) {
        b.insert(*R2);
        a.insert(rev(*R2));
        R2++;
      }
    else
      continue;
    for (auto p : a) {
      s.erase(p);
      t.erase(rev(p));
    }
    return solve(s, t) + solve(a, b);
  }
  return 1;
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  set<pair<int, int> > s, t;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    s.insert({x, y});
    t.insert({y, x});
  }
  cout << solve(s, t) << endl;
  return 0;
}
