#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 11;
const long long oo = 1e17 + 11;
int tcases = 1;
int n, m, res = 0;
pair<int, int> a[N];
typedef set<pair<int, int> >* Spt;
set<pair<int, int> >::iterator getNext(set<pair<int, int> >::iterator it) {
  ++it;
  return it;
}
set<pair<int, int> >::iterator getPrev(set<pair<int, int> >::iterator it) {
  --it;
  return it;
};
void solve(Spt X, Spt Y) {
  if (X->size() <= 1) {
    ++res;
    return;
  }
  set<pair<int, int> >::iterator x1 = X->begin(), x2 = getPrev(X->end());
  set<pair<int, int> >::iterator y1 = Y->begin(), y2 = getPrev(Y->end());
  int nn = X->size(), total = 1;
  while (x1 != x2) {
    auto ix1 = getNext(x1), ix2 = getPrev(x2);
    if (x1->first + 1 < ix1->first) {
      set<pair<int, int> >::iterator it = X->begin();
      Spt Sx = new set<pair<int, int> >(), Sy = new set<pair<int, int> >();
      while (true) {
        Sx->insert(*it);
        Sy->insert(make_pair(it->second, it->first));
        if (it == x1) break;
        it = getNext(it);
      }
      for (auto el : *Sx) {
        X->erase(X->find(el));
        Y->erase(Y->find(make_pair(el.second, el.first)));
      }
      solve(Sx, Sy);
      solve(X, Y);
      return;
    } else if (x2->first - 1 > getPrev(x2)->first) {
      set<pair<int, int> >::iterator it = getPrev(X->end());
      Spt Sx = new set<pair<int, int> >(), Sy = new set<pair<int, int> >();
      while (true) {
        Sx->insert(*it);
        Sy->insert(make_pair(it->second, it->first));
        if (it == x2) break;
        it = getPrev(it);
      }
      for (auto el : *Sx) {
        X->erase(X->find(el));
        Y->erase(Y->find(make_pair(el.second, el.first)));
      }
      solve(Sx, Sy);
      solve(X, Y);
      return;
    }
    auto iy1 = getNext(y1), iy2 = getPrev(y2);
    if (y1->first + 1 < iy1->first) {
      set<pair<int, int> >::iterator it = Y->begin();
      Spt Sx = new set<pair<int, int> >(), Sy = new set<pair<int, int> >();
      while (true) {
        Sy->insert(*it);
        Sx->insert(make_pair(it->second, it->first));
        if (it == y1) break;
        it = getNext(it);
      }
      for (auto el : *Sy) {
        Y->erase(Y->find(el));
        X->erase(X->find(make_pair(el.second, el.first)));
      }
      solve(Sx, Sy);
      solve(X, Y);
      return;
    } else if (y2->first - 1 > iy2->first) {
      set<pair<int, int> >::iterator it = getPrev(Y->end());
      Spt Sx = new set<pair<int, int> >(), Sy = new set<pair<int, int> >();
      while (true) {
        Sy->insert(*it);
        Sx->insert(make_pair(it->second, it->first));
        if (it == y2) break;
        it = getPrev(it);
      }
      for (auto el : *Sy) {
        Y->erase(Y->find(el));
        X->erase(X->find(make_pair(el.second, el.first)));
      }
      solve(Sx, Sy);
      solve(X, Y);
      return;
    }
    if (ix1 == x2) break;
    x1 = ix1;
    x2 = ix2;
    y1 = iy1;
    y2 = iy2;
  }
  ++res;
}
void testcase() {
  cin >> n;
  set<pair<int, int> > sx, sy;
  for (int i = 1; i <= n; ++i) {
    int x, y;
    cin >> x >> y;
    sx.insert(make_pair(x, y));
    sy.insert(make_pair(y, x));
  }
  solve(&sx, &sy);
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  for (int i = 1; i <= tcases; ++i) testcase();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
