#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
void Move(set<pair<int, int> >& set00, set<pair<int, int> >& set01,
          set<pair<int, int> >& set10, set<pair<int, int> >& set11,
          pair<int, int> item) {
  set00.erase(item);
  set10.insert(item);
  swap(item.first, item.second);
  set01.erase(item);
  set11.insert(item);
}
int split(set<pair<int, int> >& Sx, set<pair<int, int> >& Sy) {
  if ((int)Sx.size() == 1) return 1;
  assert((int)Sx.size() == (int)Sy.size());
  auto x_fw = Sx.begin(), x_fd = --Sx.end();
  auto y_fw = Sy.begin(), y_fd = --Sy.end();
  set<pair<int, int> > nSx;
  set<pair<int, int> > nSy;
  do {
    int x_prev = x_fw->first;
    x_fw++;
    if (abs(x_fw->first - x_prev) > 1) {
      while (Sx.begin()->first <= x_prev) Move(Sx, Sy, nSx, nSy, *Sx.begin());
      break;
    }
    x_prev = x_fd->first;
    x_fd--;
    if (abs(x_fd->first - x_prev) > 1) {
      while (Sx.rbegin()->first >= x_prev) Move(Sx, Sy, nSx, nSy, *Sx.rbegin());
      break;
    }
    int y_prev = y_fw->first;
    y_fw++;
    if (abs(y_fw->first - y_prev) > 1) {
      while (Sy.begin()->first <= y_prev) Move(Sy, Sx, nSy, nSx, *Sy.begin());
      break;
    }
    y_prev = y_fd->first;
    y_fd--;
    if (abs(y_fd->first - y_prev) > 1) {
      while (Sy.rbegin()->first >= y_prev) Move(Sy, Sx, nSy, nSx, *Sy.rbegin());
      break;
    }
  } while (*x_fw < *x_fd);
  if (nSx.empty()) return 1;
  return split(Sx, Sy) + split(nSx, nSy);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  set<pair<int, int> > Sx;
  set<pair<int, int> > Sy;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    int y;
    cin >> y;
    Sx.insert(pair<int, int>(x, y));
    Sy.insert(pair<int, int>(y, x));
  }
  cout << split(Sx, Sy) << endl;
}
