#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
set<pair<int, int> > X, Y;
int n, x[N], y[N];
int solve(set<pair<int, int> > &a, set<pair<int, int> > &b) {
  set<pair<int, int> >::iterator ta1 = a.begin(), ta2 = --a.end(),
                                 tb1 = b.begin(), tb2 = --b.end(), nxt, t, ed1,
                                 ed2;
  while (*ta1 <= *ta2 || *tb1 <= *tb2) {
    assert(!a.empty());
    if (ta1 != --a.end()) {
      nxt = ++ta1;
      --ta1;
      set<pair<int, int> > aa, bb;
      if (ta1->first + 1 < nxt->first) {
        for (t = a.begin(); t != nxt;) {
          int u = t->second;
          ++t;
          aa.insert(pair<int, int>(x[u], u)),
              bb.insert(pair<int, int>(y[u], u)),
              b.erase(pair<int, int>(y[u], u)),
              a.erase(pair<int, int>(x[u], u));
        }
        return solve(aa, bb) + solve(a, b);
      }
    }
    if (ta2 != a.begin()) {
      nxt = --ta2;
      ++ta2;
      set<pair<int, int> > aa, bb;
      if (ta2->first - 1 > nxt->first) {
        for (t = --a.end(); t != nxt;) {
          int u = t->second;
          --t;
          aa.insert(pair<int, int>(x[u], u)),
              bb.insert(pair<int, int>(y[u], u)),
              b.erase(pair<int, int>(y[u], u)),
              a.erase(pair<int, int>(x[u], u));
        }
        return solve(aa, bb) + solve(a, b);
      }
    }
    if (tb1 != --b.end()) {
      nxt = ++tb1;
      --tb1;
      set<pair<int, int> > aa, bb;
      if (tb1->first + 1 < nxt->first) {
        for (t = b.begin(); t != nxt;) {
          int u = t->second;
          ++t;
          aa.insert(pair<int, int>(x[u], u)),
              bb.insert(pair<int, int>(y[u], u)),
              b.erase(pair<int, int>(y[u], u)),
              a.erase(pair<int, int>(x[u], u));
        }
        return solve(aa, bb) + solve(a, b);
      }
    }
    if (tb2 != b.begin()) {
      nxt = --tb2;
      ++tb2;
      set<pair<int, int> > aa, bb;
      if (tb2->first - 1 > nxt->first) {
        for (t = --b.end(); t != nxt;) {
          int u = t->second;
          --t;
          aa.insert(pair<int, int>(x[u], u)),
              bb.insert(pair<int, int>(y[u], u)),
              b.erase(pair<int, int>(y[u], u)),
              a.erase(pair<int, int>(x[u], u));
        }
        return solve(aa, bb) + solve(a, b);
      }
    }
    ed1 = --a.end(), ed2 = --b.end();
    if (ta1 == ed1 && tb1 == ed2) break;
    if (ta1 != ed1) ++ta1, --ta2;
    if (tb1 != ed2) ++tb1, --tb2;
  }
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x[i], &y[i]);
    X.insert(pair<int, int>(x[i], i));
    Y.insert(pair<int, int>(y[i], i));
  }
  printf("%d\n", solve(X, Y));
  return 0;
}
