#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 333;
const long long linf = 1e18 + 333;
const int N = 1e5 + 5;
int n;
int solve(set<pair<int, int> > &sx, set<pair<int, int> > &sy) {
  set<pair<int, int> > nx, ny;
  set<pair<int, int> >::iterator ix = sx.begin();
  set<pair<int, int> >::iterator iy = sy.begin();
  set<pair<int, int> >::reverse_iterator jx = sx.rbegin();
  set<pair<int, int> >::reverse_iterator jy = sy.rbegin();
  int xb = ix->first;
  int yb = iy->first;
  int xe = jx->first;
  int ye = jy->first;
  while (ix != sx.end()) {
    if (ix->first - xb > 1) {
      while (sx.begin()->first <= xb + 1) {
        int x = sx.begin()->first;
        int y = sx.begin()->second;
        nx.insert(pair<int, int>(x, y));
        ny.insert(pair<int, int>(y, x));
        sx.erase(pair<int, int>(x, y));
        sy.erase(pair<int, int>(y, x));
      }
      return solve(sx, sy) + solve(nx, ny);
    }
    if (iy->first - yb > 1) {
      while (sy.begin()->first <= yb + 1) {
        int x = sy.begin()->second;
        int y = sy.begin()->first;
        nx.insert(pair<int, int>(x, y));
        ny.insert(pair<int, int>(y, x));
        sx.erase(pair<int, int>(x, y));
        sy.erase(pair<int, int>(y, x));
      }
      return solve(sx, sy) + solve(nx, ny);
    }
    if (xe - jx->first > 1) {
      while (xe - 1 <= sx.rbegin()->first) {
        int x = sx.rbegin()->first;
        int y = sx.rbegin()->second;
        nx.insert(pair<int, int>(x, y));
        ny.insert(pair<int, int>(y, x));
        sx.erase(pair<int, int>(x, y));
        sy.erase(pair<int, int>(y, x));
      }
      return solve(sx, sy) + solve(nx, ny);
    }
    if (ye - jy->first > 1) {
      while (ye - 1 <= sy.rbegin()->first) {
        int x = sy.rbegin()->second;
        int y = sy.rbegin()->first;
        nx.insert(pair<int, int>(x, y));
        ny.insert(pair<int, int>(y, x));
        sx.erase(pair<int, int>(x, y));
        sy.erase(pair<int, int>(y, x));
      }
      return solve(sx, sy) + solve(nx, ny);
    }
    if (*ix > *jx) break;
    xb = ix->first;
    yb = iy->first;
    xe = jx->first;
    ye = jy->first;
    ix++;
    iy++;
    jx++;
    jy++;
  }
  return 1;
}
int main() {
  ios ::sync_with_stdio(0);
  cin >> n;
  set<pair<int, int> > sx, sy;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    sx.insert(pair<int, int>(x, y));
    sy.insert(pair<int, int>(y, x));
  }
  cout << solve(sx, sy) << endl;
  return 0;
}
