#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > sx, sy;
int i, j, k, n, m, x, y, z;
int solve(set<pair<int, int> > &sx, set<pair<int, int> > &sy) {
  set<pair<int, int> > nx, ny;
  set<pair<int, int> >::iterator xb = sx.begin();
  set<pair<int, int> >::iterator yb = sy.begin();
  set<pair<int, int> >::reverse_iterator xe = sx.rbegin();
  set<pair<int, int> >::reverse_iterator ye = sy.rbegin();
  int nxb = xb->first;
  int nyb = yb->first;
  int nxe = xe->first;
  int nye = ye->first;
  int s = sx.size();
  while (xb != sx.end()) {
    if ((xb->first) - nxb > 1) {
      while (nxb >= sx.begin()->first) {
        int x = sx.begin()->first;
        int y = sx.begin()->second;
        nx.insert(make_pair(x, y));
        ny.insert(make_pair(y, x));
        sx.erase(make_pair(x, y));
        sy.erase(make_pair(y, x));
      }
      return solve(nx, ny) + solve(sx, sy);
    }
    if ((yb->first) - nyb > 1) {
      while (nyb >= sy.begin()->first) {
        int x = sy.begin()->second;
        int y = sy.begin()->first;
        nx.insert(make_pair(x, y));
        ny.insert(make_pair(y, x));
        sx.erase(make_pair(x, y));
        sy.erase(make_pair(y, x));
      }
      return solve(nx, ny) + solve(sx, sy);
    }
    if (nxe - (xe->first) > 1) {
      while (nxe <= sx.rbegin()->first) {
        int x = sx.rbegin()->first;
        int y = sx.rbegin()->second;
        nx.insert(make_pair(x, y));
        ny.insert(make_pair(y, x));
        sx.erase(make_pair(x, y));
        sy.erase(make_pair(y, x));
      }
      return solve(nx, ny) + solve(sx, sy);
    }
    if (nye - (ye->first) > 1) {
      while (nye <= sy.rbegin()->first) {
        int x = sy.rbegin()->second;
        int y = sy.rbegin()->first;
        nx.insert(make_pair(x, y));
        ny.insert(make_pair(y, x));
        sx.erase(make_pair(x, y));
        sy.erase(make_pair(y, x));
      }
      return solve(nx, ny) + solve(sx, sy);
    }
    if (*xb > *xe) break;
    nxb = xb->first;
    xb++;
    nxe = xe->first;
    xe++;
    nyb = yb->first;
    yb++;
    nye = ye->first;
    ye++;
  }
  return 1;
}
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    scanf("%d %d", &x, &y);
    sx.insert(make_pair(x, y));
    sy.insert(make_pair(y, x));
  }
  cout << solve(sx, sy) << '\n';
}
