#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:536870912")
#pragma warning(disable : 4996)
using namespace std;
const int N = 6e5 + 100, INF = 1e9 + 100;
int lb[N], rb[N], sz[N], a[N], b[N], up[N], lc[N], rc[N], mx[N];
int root = 0;
void push(int x) {
  if (up[x]) {
    if (lc[x]) up[lc[x]] += up[x];
    if (rc[x]) up[rc[x]] += up[x];
    mx[x] += up[x];
    a[x] += up[x];
    up[x] = 0;
  }
}
void upd(int x) {
  if (!x) return;
  push(x);
  push(lc[x]);
  push(rc[x]);
  mx[x] = max(max(mx[lc[x]], mx[rc[x]]), a[x]);
  sz[x] = sz[lc[x]] + 1 + sz[rc[x]];
}
int merge(int x, int y) {
  upd(x);
  upd(y);
  if (!x) return y;
  if (!y) return x;
  if (b[x] > b[y]) {
    rc[x] = merge(rc[x], y);
    upd(x);
    return x;
  }
  lc[y] = merge(x, lc[y]);
  upd(y);
  return y;
}
pair<int, int> splitK(int x, int k) {
  if (!k) return {0, x};
  upd(x);
  if (sz[lc[x]] >= k) {
    auto p = splitK(lc[x], k);
    lc[x] = p.second;
    upd(x);
    return {p.first, x};
  }
  auto p = splitK(rc[x], k - sz[lc[x]] - 1);
  rc[x] = p.first;
  upd(x);
  return {x, p.second};
}
pair<int, int> splitVal(int x, int k) {
  if (!x) return {0, 0};
  upd(x);
  if (mx[lc[x]] >= k) {
    auto p = splitVal(lc[x], k);
    lc[x] = p.second;
    upd(x);
    return {p.first, x};
  }
  if (a[x] >= k) {
    int t = lc[x];
    lc[x] = 0;
    upd(x);
    return {t, x};
  }
  auto p = splitVal(rc[x], k);
  rc[x] = p.first;
  upd(x);
  return {x, p.second};
}
int lwrBd(int x, int d) {
  if (!x) return 1;
  upd(x);
  if (mx[lc[x]] >= d) return lwrBd(lc[x], d);
  if (a[x] >= d) return sz[lc[x]] + 1;
  return lwrBd(rc[x], d) + sz[lc[x]] + 1;
}
int main() {
  srand(time(0));
  for (int i = 1; i < N; i++) {
    b[i] = (rand() << 15) + rand();
    sz[i] = 1;
  }
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d%d", &lb[i], &rb[i]);
  root = 1;
  for (int i = 2; i <= n + 2; i++) {
    a[i] = INF;
    mx[i] = INF;
    root = merge(root, i);
  }
  for (int i = 0; i < n; i++) {
    auto g = splitVal(root, rb[i]);
    auto h = splitVal(g.first, lb[i]);
    auto w = splitK(g.second, 1);
    if (h.second) up[h.second]++;
    a[w.first] = lb[i];
    root = merge(merge(h.first, w.first), merge(h.second, w.second));
  }
  printf("%d", lwrBd(root, INF) - 2);
  return 0;
}
