#include <bits/stdc++.h>
using namespace std;
typedef struct item *pitem;
struct item {
  int prior, value, cnt, add;
  bool rev;
  pitem l, r;
  item(int val) {
    prior = rand();
    value = val;
    cnt = 1;
    rev = false;
    l = r = NULL;
    add = 0;
  }
};
int cnt(pitem it) { return it ? it->cnt : 0; }
void upd_cnt(pitem it) {
  if (it) it->cnt = cnt(it->l) + cnt(it->r) + 1;
}
void push(pitem it) {
  if (it && it->rev) {
    it->rev = false;
    swap(it->l, it->r);
    if (it->l) it->l->rev ^= true;
    if (it->r) it->r->rev ^= true;
  }
  if (it) {
    if (it->l) it->l->add += it->add;
    if (it->r) it->r->add += it->add;
    it->value += it->add;
    it->add = 0;
  }
}
void merge(pitem &t, pitem l, pitem r) {
  push(l);
  push(r);
  if (!l || !r)
    t = l ? l : r;
  else if (l->prior > r->prior)
    merge(l->r, l->r, r), t = l;
  else
    merge(r->l, l, r->l), t = r;
  upd_cnt(t);
}
void split(pitem t, pitem &l, pitem &r, int key, int add = 0) {
  if (!t) return void(l = r = 0);
  push(t);
  int cur_key = t->value;
  if (key <= cur_key)
    split(t->l, l, t->l, key, add), r = t;
  else
    split(t->r, t->r, r, key, add + 1 + cnt(t->l)), l = t;
  upd_cnt(t);
}
void splitbsz(pitem t, pitem &l, pitem &r, int key, int add = 0) {
  if (!t) return void(l = r = 0);
  push(t);
  int cur_key = add + cnt(t->l);
  if (key <= cur_key)
    splitbsz(t->l, l, t->l, key, add), r = t;
  else
    splitbsz(t->r, t->r, r, key, add + 1 + cnt(t->l)), l = t;
  upd_cnt(t);
}
void ins(pitem &t, int x) {
  pitem nw = new item(x);
  pitem l, r;
  split(t, l, r, x);
  merge(t, l, nw);
  merge(t, t, r);
}
void output(pitem t) {
  if (!t) return;
  push(t);
  output(t->l);
  if (t->value < 1.5e9) printf("%d ", t->value);
  output(t->r);
}
int ans;
void cntsmall(pitem t) {
  if (!t) return;
  push(t);
  cntsmall(t->l);
  if (t->value < 1.5e9) ans++;
  cntsmall(t->r);
}
int n;
int vls[100];
void uvls(int l, int r) {
  for (int i = r - 1; i >= l; i--) {
    vls[i] = max(vls[i], vls[i - 1] + 1);
  }
  for (int i = (1); i < (100); i++) vls[i] = max(vls[i], vls[i - 1]);
}
void delfrst(pitem &t) {
  if (!t) return;
  pitem frst, rst;
  splitbsz(t, frst, rst, 1);
  t = rst;
}
int main() {
  scanf("%d", &n);
  pitem t = NULL;
  ins(t, 0);
  for (int i = (0); i < (n + 5); i++) ins(t, 2e9 + i);
  for (int _ = (0); _ < (n); _++) {
    int l, r;
    scanf("%d %d", &l, &r);
    pitem lsl, btw, ger;
    split(t, lsl, t, l);
    split(t, btw, ger, r);
    if (btw) btw->add++;
    delfrst(ger);
    pitem nw = new item(l);
    merge(t, lsl, nw);
    merge(t, t, btw);
    merge(t, t, ger);
  }
  cntsmall(t);
  printf("%d\n", ans - 1);
}
