#include <bits/stdc++.h>
using namespace std;
const int inf = 0x20202020;
const long long mod = 1000000007;
const double eps = 1e-9;
const double pi = 3.1415926535897932384626;
const int DX[] = {1, 0, -1, 0}, DY[] = {0, 1, 0, -1};
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long powmod(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 101000;
struct pointset {
  set<pair<int, int> > px, py;
  map<int, int> cntx, cnty;
  set<int> rx, ry;
  int queryx() {
    if (px.empty()) return -1;
    while (1) {
      int cx = *rx.begin();
      if (cx < px.begin()->first)
        rx.erase(rx.begin());
      else {
        if (cx > px.rbegin()->first) return -1;
        return cx;
      }
    }
  }
  int queryy() {
    if (py.empty()) return -1;
    while (1) {
      int cy = *ry.begin();
      if (cy < py.begin()->first)
        ry.erase(ry.begin());
      else {
        if (cy > py.rbegin()->first) return -1;
        return cy;
      }
    }
  }
  void build(vector<pair<int, int> > &c) {
    for (int i = 0; i < ((int)(c).size()); i++) {
      cntx[c[i].first]++, cnty[c[i].second]++;
      ;
      px.insert(c[i]);
      py.insert(make_pair(c[i].second, c[i].first));
    }
    for (int i = 0; i < ((int)(c).size()); i++) {
      if (!cntx.count(c[i].first + 1)) rx.insert(c[i].first + 1);
      if (!cnty.count(c[i].second + 1)) ry.insert(c[i].second + 1);
    }
  }
  void del(pair<int, int> p) {
    px.erase(p);
    py.erase(make_pair(p.second, p.first));
    if ((--cntx[p.first]) == 0) rx.insert(p.first);
    if ((--cnty[p.second]) == 0) ry.insert(p.second);
  }
} tmp[N];
int tp = 0;
int n, x, y, ret;
void gao(pointset &a) {
  int px = a.queryx(), py = a.queryy();
  if (px < 0 && py < 0) {
    ret += 1;
    return;
  }
  if (px >= 0) {
    vector<pair<int, int> > pl, pr;
    set<pair<int, int> >::iterator it = a.px.begin();
    set<pair<int, int> >::reverse_iterator rit = a.px.rbegin();
    while (it->first < px && rit->first > px) {
      pl.push_back(*it);
      pr.push_back(*rit);
      ++it;
      ++rit;
    }
    if (it->first < px) {
      pointset &b = tmp[tp++];
      b.build(pr);
      gao(b);
      for (int j = 0; j < ((int)(pr).size()); j++) a.del(pr[j]);
      gao(a);
    } else {
      pointset &b = tmp[tp++];
      b.build(pl);
      gao(b);
      for (int j = 0; j < ((int)(pl).size()); j++) a.del(pl[j]);
      gao(a);
    }
  } else {
    vector<pair<int, int> > pl, pr;
    set<pair<int, int> >::iterator it = a.py.begin();
    set<pair<int, int> >::reverse_iterator rit = a.py.rbegin();
    while (it->first < py && rit->first > py) {
      pl.push_back(make_pair(it->second, it->first));
      pr.push_back(make_pair(rit->second, rit->first));
      ++it;
      ++rit;
    }
    if (it->first < py) {
      pointset &b = tmp[tp++];
      b.build(pr);
      gao(b);
      for (int j = 0; j < ((int)(pr).size()); j++) a.del(pr[j]);
      gao(a);
    } else {
      pointset &b = tmp[tp++];
      b.build(pl);
      gao(b);
      for (int j = 0; j < ((int)(pl).size()); j++) a.del(pl[j]);
      gao(a);
    }
  }
}
vector<pair<int, int> > vr;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &x, &y);
    x += 1000000000;
    y += 1000000000;
    vr.push_back(make_pair(x, y));
  }
  pointset &p = tmp[tp++];
  p.build(vr);
  gao(p);
  printf("%d\n", ret);
}
