#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 2;
int n, ans;
struct Point {
  int x, y;
};
struct cmp1 {
  bool operator()(const Point& a, const Point& b) {
    return a.x < b.x || (a.x == b.x && a.y < b.y);
  }
};
struct cmp2 {
  bool operator()(const Point& a, const Point& b) {
    return a.y < b.y || (a.y == b.y && a.x < b.x);
  }
};
template <typename _Tp>
inline void IN(_Tp& x) {
  char ch;
  bool flag = 0;
  x = 0;
  while (ch = getchar(), !isdigit(ch))
    if (ch == '-') flag = 1;
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  if (flag) x = -x;
}
inline void solve(set<Point, cmp1>& sx, set<Point, cmp2>& sy) {
  auto left = sx.begin(), right = --sx.end();
  auto down = sy.begin(), up = --sy.end();
  int siz = sx.size() >> 1;
  for (int i = 1; i <= siz; ++i) {
    auto tmpl = left++;
    if (tmpl->x + 1 < left->x) {
      set<Point, cmp1> s1;
      set<Point, cmp2> s2;
      left = ++tmpl;
      for (tmpl = sx.begin(); tmpl != left;) {
        auto now = tmpl++;
        s1.insert(*now), s2.insert(*now), sx.erase(*now), sy.erase(*now);
      }
      solve(sx, sy);
      solve(s1, s2);
      return;
    }
    auto tmpr = right--;
    if (tmpr->x - 1 > right->x) {
      set<Point, cmp1> s1;
      set<Point, cmp2> s2;
      right = --tmpr;
      for (tmpr = --sx.end(); tmpr != right;) {
        auto now = tmpr--;
        s1.insert(*now), s2.insert(*now), sx.erase(*now), sy.erase(*now);
      }
      solve(sx, sy);
      solve(s1, s2);
      return;
    }
    auto tmpd = down++;
    if (tmpd->y + 1 < down->y) {
      set<Point, cmp1> s1;
      set<Point, cmp2> s2;
      down = ++tmpd;
      for (tmpd = sy.begin(); tmpd != down;) {
        auto now = tmpd++;
        s1.insert(*now), s2.insert(*now), sx.erase(*now), sy.erase(*now);
      }
      solve(sx, sy);
      solve(s1, s2);
      return;
    }
    auto tmpu = up--;
    if (tmpu->y - 1 > up->y) {
      set<Point, cmp1> s1;
      set<Point, cmp2> s2;
      up = --tmpu;
      for (tmpu = --sy.end(); tmpu != up;) {
        auto now = tmpu--;
        s1.insert(*now), s2.insert(*now), sx.erase(*now), sy.erase(*now);
      }
      solve(sx, sy);
      solve(s1, s2);
      return;
    }
  }
  ++ans;
}
set<Point, cmp1> sx;
set<Point, cmp2> sy;
int main() {
  IN(n);
  while (n--) {
    int x, y;
    IN(x), IN(y);
    sx.insert((Point){x, y}), sy.insert((Point){x, y});
  }
  solve(sx, sy);
  printf("%d\n", ans);
  return 0;
}
