#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
  if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
  if (a < b) a = b;
}
int N;
pair<int, int> arr[100013];
vector<pair<set<pair<int, int> >, set<pair<int, int> > > > to;
int ans;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N;
  for (auto i = (0); i < (N); i++) cin >> arr[i].first >> arr[i].second;
  set<pair<int, int> > beg, begr;
  for (auto i = (0); i < (N); i++) {
    beg.insert(arr[i]);
    begr.insert({arr[i].second, arr[i].first});
  }
  to.push_back({beg, begr});
  while (!to.empty()) {
    int sz = ((int)((to.back().first).size()));
    if (sz == 1) {
      to.pop_back();
      ans++;
      continue;
    }
    auto it = to.back().first.begin();
    auto It = to.back().second.begin();
    auto IT = prev(to.back().first.end());
    auto iT = prev(to.back().second.end());
    pair<set<pair<int, int> >, set<pair<int, int> > > rec;
    bool ok = false;
    for (auto i = (0); i < ((sz + 1) >> 1); i++) {
      if (next(it)->first > it->first + 1) {
        for (auto jt = to.back().first.begin();;) {
          pair<int, int> p = *jt;
          rec.first.insert(p);
          rec.second.insert({p.second, p.first});
          to.back().second.erase({p.second, p.first});
          if (jt == it) break;
          jt = to.back().first.erase(jt);
        }
        to.back().first.erase(it);
        ok = true;
        break;
      }
      if (next(It)->first > It->first + 1) {
        for (auto jt = to.back().second.begin();;) {
          pair<int, int> p = *jt;
          rec.second.insert(p);
          rec.first.insert({p.second, p.first});
          to.back().first.erase({p.second, p.first});
          if (jt == It) break;
          jt = to.back().second.erase(jt);
        }
        to.back().second.erase(It);
        ok = true;
        break;
      }
      if (prev(IT)->first < IT->first - 1) {
        for (auto jt = prev(to.back().first.end());;) {
          pair<int, int> p = *jt;
          rec.first.insert(p);
          rec.second.insert({p.second, p.first});
          to.back().second.erase({p.second, p.first});
          if (jt == IT) break;
          jt = to.back().first.erase(jt);
          jt--;
        }
        to.back().first.erase(IT);
        ok = true;
        break;
      }
      if (prev(iT)->first < iT->first - 1) {
        for (auto jt = prev(to.back().second.end());;) {
          pair<int, int> p = *jt;
          rec.second.insert(p);
          rec.first.insert({p.second, p.first});
          to.back().first.erase({p.second, p.first});
          if (jt == iT) break;
          jt = to.back().second.erase(jt);
          jt--;
        }
        to.back().second.erase(iT);
        ok = true;
        break;
      }
      it++;
      It++;
      IT--;
      iT--;
    }
    if (ok) {
      to.push_back(rec);
      continue;
    }
    to.pop_back();
    ans++;
  }
  cout << ans << '\n';
  return 0;
}
