#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e11;
int N;
long long L[600005];
long long R[600005];
struct SplayTree {
  int par[600005], ch[600005][2], root, tot1, sz[600005];
  long long key[600005], add[600005], sum[600005], m[600005];
  int s[600005], tot2;
  long long ar[600005];
  void Update_Add(int x, long long v) {
    if (!x) return;
    key[x] += v;
    add[x] += v, sum[x] += (long long)sz[x] * v;
    m[x] += v;
  }
  void pushdown(int x) {
    if (add[x]) {
      Update_Add(ch[x][0], add[x]);
      Update_Add(ch[x][1], add[x]);
      add[x] = 0;
    }
  }
  void upd(int x) {
    sz[x] = sz[ch[x][0]] + sz[ch[x][1]] + 1;
    sum[x] = key[x] + sum[ch[x][0]] + sum[ch[x][1]];
    m[x] = max(key[x], max(m[ch[x][0]], m[ch[x][1]]));
  }
  void ro(int x) {
    int y = par[x], d = ch[y][1] == x;
    pushdown(y);
    pushdown(x);
    ch[y][d] = ch[x][!d];
    ch[x][!d] = y;
    if (par[y]) ch[par[y]][ch[par[y]][1] == y] = x;
    par[ch[y][d]] = y;
    par[x] = par[y];
    par[y] = x;
    upd(y);
  }
  void splay(int x, int gf = 0) {
    int y;
    while ((y = par[x]) != gf) {
      if (par[y] != gf) {
        if ((ch[par[y]][1] == y) ^ (ch[par[x]][1] == x))
          ro(x);
        else
          ro(y);
      }
      ro(x);
    }
    upd(x);
    if (gf == 0) root = x;
  }
  void newnode(int &x, long long v, int p = 0, int id = 0) {
    if (tot2)
      x = s[tot2--];
    else
      x = ++tot1;
    par[x] = p;
    ch[x][0] = ch[x][1] = 0;
    sz[x] = 1;
    add[x] = 0;
    sum[x] = 0;
    key[x] = m[x] = v;
    upd(x);
  }
  void build(int &x, int l, int r, int pa) {
    if (l > r) return;
    int md = (l + r) / 2;
    newnode(x, ar[md], pa, md);
    build(ch[x][0], l, md - 1, x);
    build(ch[x][1], md + 1, r, x);
    upd(x);
  }
  int Kth(int x, int k) {
    pushdown(x);
    int t = sz[ch[x][0]] + 1;
    if (t == k) return x;
    if (t > k) return Kth(ch[x][0], k);
    return Kth(ch[x][1], k - t);
  }
  void ADD(int x, int y, long long v) {
    if (x > y) return;
    splay(Kth(root, x), 0);
    splay(Kth(root, y + 2), root);
    Update_Add(ch[ch[root][1]][0], v);
    upd(ch[root][1]);
    upd(root);
  }
  void INSERT(int x, long long v) {
    splay(Kth(root, x + 1), 0);
    splay(Kth(root, x + 2), root);
    newnode(ch[ch[root][1]][0], v, ch[root][1]);
    upd(ch[root][1]);
    upd(root);
  }
  void erase(int x) {
    if (!x) return;
    s[++tot2] = x;
    erase(ch[x][0]);
    erase(ch[x][1]);
  }
  void DELETE(int x) {
    splay(Kth(root, x), 0);
    splay(Kth(root, x + 2), root);
    erase(ch[ch[root][1]][0]);
    par[ch[ch[root][1]][0]] = 0;
    ch[ch[root][1]][0] = 0;
    upd(ch[root][1]);
    upd(root);
  }
  long long qry(int x) {
    splay(Kth(root, x), 0);
    splay(Kth(root, x + 2), root);
    return sum[ch[ch[root][1]][0]];
  }
  void init() {
    root = tot1 = tot2 = 0;
    for (int i = 0; i < 600005; i++) key[i] = INF;
    ch[root][0] = ch[root][1] = par[root] = 0;
    add[root] = sz[root] = 0;
    sum[root] = 0;
    m[root] = INF;
    newnode(root, INF, 0);
    newnode(ch[root][1], INF, root);
    for (int i = 0; i <= N + 1; i++) ar[i] = INF;
    for (int i = 0; i < N; i++) cin >> L[i] >> R[i];
    ar[0] = 0;
    ar[1] = L[0];
    build(ch[ch[root][1]][0], 0, N + 2, ch[root][1]);
    upd(ch[root][1]);
    upd(root);
  }
  int less(int x, long long k) {
    pushdown(x);
    if (x == root) {
      splay(Kth(root, 1), 0);
      splay(Kth(root, N + 2), root);
      return less(ch[ch[root][1]][0], k);
    }
    long long v = key[x];
    if (sz[x] <= 1) return (key[x] < k);
    if (v >= k) return less(ch[x][0], k);
    return sz[ch[x][0]] + (key[x] < k) + less(ch[x][1], k);
  }
  void print() {
    for (int i = 1; i <= N + 1; i++) printf("%d | %lld\n", i, qry(i));
  }
} Tree;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  Tree.init();
  for (int i = 1; i < N; i++) {
    int p1 = Tree.less(Tree.root, L[i]);
    int p2 = Tree.less(Tree.root, R[i]);
    Tree.DELETE(p2 + 1);
    Tree.INSERT(p1, L[i]);
    Tree.ADD(p1 + 2, p2 + 1, 1);
  }
  for (int i = N + 1; i >= 1; i--) {
    if (Tree.qry(i) < INF) {
      printf("%d\n", i - 1);
      return 0;
    }
  }
}
