#include <bits/stdc++.h>
using namespace std;
int const MAXN = 1e5 + 8;
int const delta = 1000000007;
inline void mov(set<pair<int, int> >& px, set<pair<int, int> >& py,
                set<pair<int, int> >& px2, set<pair<int, int> >& py2,
                pair<int, int> P) {
  px.erase(P);
  py.erase(make_pair(P.second, P.first));
  px2.insert(P);
  py2.insert(make_pair(P.second, P.first));
}
inline int solve(set<pair<int, int> >& px, set<pair<int, int> >& py) {
  if (px.size() <= 1) return 1;
  set<pair<int, int> > px2, py2;
  set<pair<int, int> >::iterator lx = px.begin(), rx = px.end();
  rx--;
  set<pair<int, int> >::iterator ly = py.begin(), ry = py.end();
  ry--;
  while (*lx < *rx) {
    int x = lx->first;
    lx++;
    if (lx->first - x > 1) {
      while (px.begin()->first <= x) mov(px, py, px2, py2, *px.begin());
      return (solve(px, py) + solve(px2, py2));
    }
    x = rx->first;
    rx--;
    if (x - rx->first > 1) {
      while (px.rbegin()->first >= x) mov(px, py, px2, py2, *px.rbegin());
      return (solve(px, py) + solve(px2, py2));
    }
    int y = ly->first;
    ly++;
    if (ly->first - y > 1) {
      while (py.begin()->first <= y) mov(py, px, py2, px2, *py.begin());
      return (solve(px, py) + solve(px2, py2));
    }
    y = ry->first;
    ry--;
    if (y - ry->first > 1) {
      while (py.rbegin()->first >= y) mov(py, px, py2, px2, *py.rbegin());
      return (solve(px, py) + solve(px2, py2));
    }
  }
  return 1;
}
int main() {
  std::ios::sync_with_stdio(0);
  ;
  cin.tie(0);
  cout.tie(0);
  set<pair<int, int> > px, py;
  int n;
  cin >> n;
  int f, s;
  for (int i = 0; i < n; i++) {
    cin >> f >> s;
    px.insert(make_pair(f, s));
    py.insert(make_pair(s, f));
  }
  cout << solve(px, py);
  return 0;
}
