#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
int n;
struct TNODE {
  int Vkey, Vfix, Vsiz, Vlzy;
  TNODE *ch[2];
};
struct TREAP {
  TNODE Tpol[N * 2], *Tcnt, *Trt, *Tnul;
  void Init() {
    Tcnt = Trt = Tnul = Tpol;
    Tnul->ch[0] = Tnul->ch[1] = Tnul;
    Tnul->Vkey = 0;
    Tnul->Vsiz = 0;
    Tnul->Vfix = 0;
  }
  TNODE *NewNode(int Vv) {
    TNODE *p = ++Tcnt;
    p->ch[0] = p->ch[1] = Tnul;
    p->Vkey = Vv;
    p->Vlzy = 0;
    p->Vsiz = 1;
    p->Vfix = (rand() % 12343) * (rand() % 2134);
    return p;
  }
  void PushDown(TNODE *Pu) {
    if (Pu->ch[0] != Tnul) {
      Pu->ch[0]->Vlzy += Pu->Vlzy;
      Pu->ch[0]->Vkey += Pu->Vlzy;
    }
    if (Pu->ch[1] != Tnul) {
      Pu->ch[1]->Vlzy += Pu->Vlzy;
      Pu->ch[1]->Vkey += Pu->Vlzy;
    }
    Pu->Vlzy = 0;
  }
  void PushUp(TNODE *Pu) { Pu->Vsiz = Pu->ch[0]->Vsiz + Pu->ch[1]->Vsiz + 1; }
  TNODE *Merge(TNODE *Pu, TNODE *Pv) {
    if (Pu == Tnul) return Pv;
    if (Pv == Tnul) return Pu;
    PushDown(Pu);
    PushDown(Pv);
    if (Pu->Vfix <= Pv->Vfix) {
      Pu->ch[1] = Merge(Pu->ch[1], Pv);
      PushUp(Pu);
      return Pu;
    } else {
      Pv->ch[0] = Merge(Pu, Pv->ch[0]);
      PushUp(Pv);
      return Pv;
    }
  }
  typedef pair<TNODE *, TNODE *> DNODE;
  DNODE Split(TNODE *Pu, int Vv) {
    DNODE Rr(Tnul, Tnul);
    PushDown(Pu);
    if (Pu == Tnul) return Rr;
    if (Vv < Pu->Vkey) {
      Rr = Split(Pu->ch[0], Vv);
      Pu->ch[0] = Rr.second;
      Rr.second = Pu;
    } else {
      Rr = Split(Pu->ch[1], Vv);
      Pu->ch[1] = Rr.first;
      Rr.first = Pu;
    }
    PushUp(Pu);
    return Rr;
  }
  DNODE SplitSize(TNODE *Pu, int Vs) {
    DNODE Rr(Tnul, Tnul);
    PushDown(Pu);
    if (Pu == Tnul) return Rr;
    if (Vs <= Pu->ch[0]->Vsiz) {
      Rr = SplitSize(Pu->ch[0], Vs);
      Pu->ch[0] = Rr.second;
      Rr.second = Pu;
    } else {
      Rr = SplitSize(Pu->ch[1], Vs - Pu->ch[0]->Vsiz - 1);
      Pu->ch[1] = Rr.first;
      Rr.first = Pu;
    }
    PushUp(Pu);
    return Rr;
  }
  void Process(int l, int r) {
    DNODE R1 = Split(Trt, l - 1);
    DNODE R2 = Split(R1.second, r - 1);
    if (R2.first != Tnul) R2.first->Vlzy++, R2.first->Vkey++;
    if (R2.second != Tnul) {
      DNODE R3 = SplitSize(R2.second, 1);
      R2.second = R3.second;
      if (R2.second != Tnul) PushUp(R2.second);
    }
    Trt = Merge(Merge(R1.first, NewNode(l)), Merge(R2.first, R2.second));
    PushUp(Trt);
  }
} Ttre;
int main() {
  Ttre.Init();
  Ttre.Trt = Ttre.NewNode(0);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int Il, Ir;
    scanf("%d%d", &Il, &Ir);
    Ttre.Process(Il, Ir);
  }
  printf("%d\n", Ttre.Trt->Vsiz - 1);
  return 0;
}
