#include <bits/stdc++.h>
using namespace std;
int n, ans, x[120000], y[120000];
set<pair<int, int> > s1, s2;
void solve(set<pair<int, int> > &s1, set<pair<int, int> > &s2) {
  set<pair<int, int> >::iterator i1 = s1.begin(), i2 = --s1.end(),
                                 j1 = s2.begin(), j2 = --s2.end();
  for (; i1 != s1.end() && j1 != s2.end(); ++i1, ++j1, --i2, --j2) {
    set<pair<int, int> >::iterator k = i1;
    ++k;
    if (k == s1.end()) break;
    if ((*i1).first >= (*i2).first && (*j1).first >= (*j2).first) break;
    if ((*i1).first + 1 < (*k).first) {
      set<pair<int, int> > ss1, ss2;
      for (set<pair<int, int> >::iterator t = s1.begin(); t != k;) {
        int u = (*t).second;
        ++t;
        s1.erase(make_pair(x[u], u));
        ss1.insert(make_pair(x[u], u));
        s2.erase(make_pair(y[u], u));
        ss2.insert(make_pair(y[u], u));
      }
      ++ans;
      solve(ss1, ss2);
      solve(s1, s2);
      return;
    }
    k = i2;
    --k;
    if ((*i2).first - 1 > (*k).first) {
      set<pair<int, int> > ss1, ss2;
      for (set<pair<int, int> >::iterator t = --s1.end(); t != k;) {
        int u = (*t).second;
        --t;
        s1.erase(make_pair(x[u], u));
        ss1.insert(make_pair(x[u], u));
        s2.erase(make_pair(y[u], u));
        ss2.insert(make_pair(y[u], u));
      }
      ++ans;
      solve(ss1, ss2);
      solve(s1, s2);
      return;
    }
    k = j1;
    ++k;
    if ((*j1).first + 1 < (*k).first) {
      set<pair<int, int> > ss1, ss2;
      for (set<pair<int, int> >::iterator t = s2.begin(); t != k;) {
        int u = (*t).second;
        ++t;
        s1.erase(make_pair(x[u], u));
        ss1.insert(make_pair(x[u], u));
        s2.erase(make_pair(y[u], u));
        ss2.insert(make_pair(y[u], u));
      }
      ++ans;
      solve(ss1, ss2);
      solve(s1, s2);
      return;
    }
    k = j2;
    --k;
    if ((*j2).first - 1 > (*k).first) {
      set<pair<int, int> > ss1, ss2;
      for (set<pair<int, int> >::iterator t = --s2.end(); t != k;) {
        int u = (*t).second;
        --t;
        s1.erase(make_pair(x[u], u));
        ss1.insert(make_pair(x[u], u));
        s2.erase(make_pair(y[u], u));
        ss2.insert(make_pair(y[u], u));
      }
      ++ans;
      solve(ss1, ss2);
      solve(s1, s2);
      return;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &x[i], &y[i]);
    s1.insert(make_pair(x[i], i));
    s2.insert(make_pair(y[i], i));
  }
  ans = 1;
  solve(s1, s2);
  printf("%d\n", ans);
  return 0;
}
