#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 79;
class point {
 public:
  int x, y, id;
  point(int X, int Y, int ID) : x(X), y(Y), id(ID) {}
};
bool cmp(point& a, point& b) { return a.x < b.x; }
vector<bool> vis(maxn, false);
array<vector<point>, 4> o;
int ans = 0;
void good(list<point>::iterator& it, list<point>& l) {
  while (it != l.end() && vis[it->id]) it = l.erase(it);
}
void solve(array<list<point>, 4>& v) {
  array<list<point>::iterator, 4> a;
  for (int i = 0; i < 4; i++) a[i] = v[i].begin(), good(a[i], v[i]);
  for (int t = 0;; t++) {
    bool did_something = false;
    for (int i = 0; i < 4; i++) {
      if (a[i] == v[i].end()) continue;
      did_something = true;
      auto it2 = next(a[i]);
      good(it2, v[i]);
      if (it2 != v[i].end() && it2->x > a[i]->x + 1) {
        array<list<point>, 4> v2;
        for (auto it = v[i].begin(); it != it2; it++)
          for (int j = 0; j < 4; j++) v2[j].push_back(o[j][it->id]);
        for (int j = 0; j < 4; j++) v2[j].sort(cmp);
        solve(v2);
        solve(v);
        return;
      }
      a[i]++;
      good(a[i], v[i]);
    }
    if (!did_something) break;
  }
  if (v[0].size()) ans++;
  for (auto it = v[0].begin(); it != v[0].end(); it++) vis[it->id] = true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0, x, y; i < n; i++) {
    cin >> x >> y;
    o[0].push_back(point(x, y, i));
    o[1].push_back(point(-x, y, i));
    o[2].push_back(point(y, x, i));
    o[3].push_back(point(-y, x, i));
  }
  array<list<point>, 4> v;
  for (int i = 0; i < 4; i++) {
    v[i].insert(v[i].begin(), o[i].begin(), o[i].end());
    v[i].sort(cmp);
  }
  solve(v);
  cout << ans << "\n";
  return 0;
}
