#include <bits/stdc++.h>
using namespace std;
struct Treap {
  int root, rnd[2 * 300005], size[2 * 300005], son[2 * 300005][2],
      val[2 * 300005], add[2 * 300005], cnt;
  int New(int x) {
    cnt++;
    rnd[cnt] = rand();
    size[cnt] = 1;
    son[cnt][0] = son[cnt][1] = add[cnt] = 0;
    val[cnt] = x;
    return cnt;
  }
  void update(int x) { size[x] = size[son[x][0]] + size[son[x][1]] + 1; }
  void pushdown(int x) {
    if (add[x]) {
      if (son[x][0]) {
        val[son[x][0]] += add[x];
        add[son[x][0]] += add[x];
      }
      if (son[x][1]) {
        val[son[x][1]] += add[x];
        add[son[x][1]] += add[x];
      }
      add[x] = 0;
    }
    update(x);
  }
  int merge(int x, int y) {
    if (!x || !y) return x + y;
    int now;
    pushdown(x);
    pushdown(y);
    if (rnd[x] <= rnd[y]) {
      now = x;
      son[x][1] = merge(son[x][1], y);
    } else {
      now = y;
      son[y][0] = merge(x, son[y][0]);
    }
    update(now);
    return now;
  }
  void split_num(int now, int &L, int &R, int num) {
    if (!now) {
      L = R = 0;
      return;
    }
    pushdown(now);
    if (val[now] < num) {
      L = now;
      split_num(son[now][1], son[now][1], R, num);
    } else {
      R = now;
      split_num(son[now][0], L, son[now][0], num);
    }
    update(now);
  }
  void split_rank(int now, int &L, int &R, int rank) {
    if (!now) {
      L = R = 0;
      return;
    }
    pushdown(now);
    int tmp = size[son[now][0]] + 1;
    if (rank >= tmp) {
      L = now;
      split_rank(son[now][1], son[now][1], R, rank - tmp);
    } else {
      R = now;
      split_rank(son[now][0], L, son[now][0], rank);
    }
    update(now);
  }
} T;
int n, m, l, r;
int main() {
  srand(0);
  cin >> n;
  T.root = T.New(-1e9 - 7);
  for (int i = 2; i <= n; i++) T.root = T.merge(T.root, T.New(1e9 + 7));
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &l, &r);
    int L, mid, die, R;
    T.split_num(T.root, L, mid, l);
    T.split_num(mid, mid, R, r);
    T.split_rank(R, die, R, 1);
    if (mid) {
      T.val[mid]++;
      T.add[mid]++;
    }
    T.root = T.merge(T.merge(L, T.New(l)), T.merge(mid, R));
  }
  int die;
  T.split_num(T.root, T.root, die, 1e9 + 7);
  printf("%d\n", T.size[T.root] - 1);
  return 0;
}
