#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int logn = log2(maxn) + 1;
pair<int, int> a[maxn];
struct cmp {
  bool operator()(const pair<int, int> &x, const pair<int, int> &y) {
    return x < y;
  }
};
struct cmp1 {
  bool operator()(const pair<int, int> &x, const pair<int, int> &y) {
    return make_pair(x.second, x.first) < make_pair(y.second, y.first);
  }
};
int res = 0;
int n;
void solve(set<pair<int, int>, cmp> &x, set<pair<int, int>, cmp1> &y) {
  int len = x.size() / 2;
  auto x_pref = x.begin(), x_suf = prev(x.end());
  auto y_pref = y.begin(), y_suf = prev(y.end());
  while (len--) {
    if (x_pref->first + 1 < next(x_pref)->first) {
      set<pair<int, int>, cmp> x1;
      set<pair<int, int>, cmp1> y1;
      x_pref = next(x_pref);
      for (auto it = x.begin(); it != x_pref;) {
        x1.insert(*it);
        y1.insert(*it);
        y.erase(*it);
        it = x.erase(it);
      }
      solve(x, y);
      solve(x1, y1);
      return;
    }
    if (y_pref->second + 1 < next(y_pref)->second) {
      set<pair<int, int>, cmp> x1;
      set<pair<int, int>, cmp1> y1;
      y_pref = next(y_pref);
      for (auto it = y.begin(); it != y_pref;) {
        x1.insert(*it);
        y1.insert(*it);
        x.erase(*it);
        it = y.erase(it);
      }
      solve(x, y);
      solve(x1, y1);
      return;
    }
    if (x_suf->first - 1 > prev(x_suf)->first) {
      set<pair<int, int>, cmp> x1;
      set<pair<int, int>, cmp1> y1;
      x_suf = prev(x_suf);
      for (auto it = prev(x.end()); it != x_suf;) {
        x1.insert(*it);
        y1.insert(*it);
        y.erase(*it);
        it = prev(x.erase(it));
      }
      solve(x, y);
      solve(x1, y1);
      return;
    }
    if (y_suf->second - 1 > prev(y_suf)->second) {
      set<pair<int, int>, cmp> x1;
      set<pair<int, int>, cmp1> y1;
      y_suf = prev(y_suf);
      for (auto it = prev(y.end()); it != y_suf;) {
        x1.insert(*it);
        y1.insert(*it);
        x.erase(*it);
        it = prev(y.erase(it));
      }
      solve(x, y);
      solve(x1, y1);
      return;
    }
    x_pref++;
    x_suf--;
    y_pref++;
    y_suf--;
  }
  res++;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (fopen("A"
            ".INP",
            "r")) {
    freopen(
        "A"
        ".INP",
        "r", stdin);
    freopen(
        "A"
        ".OUT",
        "w", stdout);
  }
  cin >> n;
  set<pair<int, int>, cmp> x;
  set<pair<int, int>, cmp1> y;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first >> a[i].second;
    x.insert(a[i]);
    y.insert(a[i]);
  }
  solve(x, y);
  cout << res;
}
