#include <bits/stdc++.h>
using namespace std;
const int RLEN = 1 << 20 | 1;
inline char gc() {
  static char ibuf[RLEN], *ib, *ob;
  (ob == ib) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
  return (ob == ib) ? EOF : *ib++;
}
inline int read() {
  char ch = getchar();
  int res = 0, f = 1;
  while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
  while (isdigit(ch)) res = (res + (res << 2) << 1) + (ch ^ 48), ch = getchar();
  return f ? res : -res;
}
const int mod = 1000000123;
inline int add(int a, int b) { return (a += b) >= mod ? a - mod : a; }
inline int dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
inline int mul(int a, int b) { return 1ll * a * b % mod; }
inline void Add(int &a, int b) { (a += b) >= mod ? a -= mod : 0; }
inline void Dec(int &a, int b) { (a -= b) < 0 ? a += mod : 0; }
inline void Mul(int &a, int b) { a = 1ll * a * b % mod; }
inline int ksm(int a, int b, int res = 1) {
  for (; b; b >>= 1, Mul(a, a)) (b & 1) && (Mul(res, a), 1);
  return res;
}
inline int Inv(int first) { return ksm(first, mod - 2); }
inline void chemx(int &a, int b) { a < b ? a = b : 0; }
inline void chemn(int &a, int b) { a > b ? a = b : 0; }
const int N = 100005;
pair<int, int> p[N];
inline pair<int, int> swp(const pair<int, int> &first) {
  return pair<int, int>(first.second, first.first);
}
inline int solve(set<pair<int, int> > &st1, set<pair<int, int> > &st2) {
  if (st1.size() == 1) return 1;
  set<pair<int, int> >::iterator lx = st1.begin();
  set<pair<int, int> >::reverse_iterator rx = st1.rbegin();
  set<pair<int, int> >::iterator ly = st2.begin();
  set<pair<int, int> >::reverse_iterator ry = st2.rbegin();
  set<pair<int, int> >::iterator End = st1.end();
  End--;
  while (lx != End) {
    int pre = (*lx).first, now;
    lx++, now = (*lx).first;
    if (now - pre > 1) {
      set<pair<int, int> > st3, st4;
      while ((*st1.begin()).first <= pre) {
        pair<int, int> xx = *st1.begin();
        st3.insert(xx), st4.insert(swp(xx));
        st1.erase(xx), st2.erase(swp(xx));
      }
      return solve(st3, st4) + solve(st1, st2);
    }
    pre = (*rx).first;
    rx++, now = (*rx).first;
    if (pre - now > 1) {
      set<pair<int, int> > st3, st4;
      while ((*st1.rbegin()).first >= pre) {
        pair<int, int> xx = *st1.rbegin();
        st3.insert(xx), st4.insert(swp(xx));
        st1.erase(xx), st2.erase(swp(xx));
      }
      return solve(st3, st4) + solve(st1, st2);
    }
    pre = (*ly).first;
    ly++, now = (*ly).first;
    if (now - pre > 1) {
      set<pair<int, int> > st3, st4;
      while ((*st2.begin()).first <= pre) {
        pair<int, int> xx = *st2.begin();
        st3.insert(swp(xx)), st4.insert(xx);
        st1.erase(swp(xx)), st2.erase(xx);
      }
      return solve(st3, st4) + solve(st1, st2);
    }
    pre = (*ry).first;
    ry++, now = (*ry).first;
    if (pre - now > 1) {
      set<pair<int, int> > st3, st4;
      while ((*st2.rbegin()).first >= pre) {
        pair<int, int> xx = (*st2.rbegin());
        st3.insert(swp(xx)), st4.insert(xx);
        st1.erase(swp(xx)), st2.erase(xx);
      }
      return solve(st3, st4) + solve(st1, st2);
    }
  };
  return 1;
}
set<pair<int, int> > st1;
set<pair<int, int> > st2;
int n;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    p[i].first = read(), p[i].second = read();
    st1.insert(p[i]);
    st2.insert(swp(p[i]));
  }
  cout << solve(st1, st2) << '\n';
}
