#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
  int val, rnd, ls, rs, tag, siz;
} tre[300005];
int root, cnt;
void pushup(int x) { tre[x].siz = tre[tre[x].ls].siz + tre[tre[x].rs].siz + 1; }
void pushdown(int x) {
  if (tre[x].tag == 0) return;
  tre[tre[x].ls].tag += tre[x].tag;
  tre[tre[x].ls].val += tre[x].tag;
  tre[tre[x].rs].tag += tre[x].tag;
  tre[tre[x].rs].val += tre[x].tag;
  tre[x].tag = 0;
}
int newnode(int val) {
  tre[++cnt].val = val;
  tre[cnt].ls = tre[cnt].rs = tre[cnt].tag = 0;
  tre[cnt].siz = 1;
  tre[cnt].rnd = rand();
  return cnt;
}
int merge(int x, int y) {
  if (!x || !y) return x ^ y;
  int res = 0;
  if (tre[x].rnd < tre[y].rnd) {
    res = x;
    pushdown(res);
    tre[x].rs = merge(tre[x].rs, y);
  } else {
    res = y;
    pushdown(res);
    tre[y].ls = merge(x, tre[y].ls);
  }
  pushup(res);
  return res;
}
void splitval(int rt, int &lrt, int &rrt, int val) {
  if (!rt) {
    lrt = rrt = 0;
    return;
  }
  pushdown(rt);
  if (tre[rt].val <= val) {
    lrt = rt;
    splitval(tre[rt].rs, tre[lrt].rs, rrt, val);
  } else {
    rrt = rt;
    splitval(tre[rt].ls, lrt, tre[rrt].ls, val);
  }
  pushup(rt);
}
void ins(int val) {
  int rx, ry;
  splitval(root, rx, ry, val - 1);
  root = merge(merge(rx, newnode(val)), ry);
}
int findkth(int rt, int k) {
  if (!rt || !k) return 0;
  int nw = rt;
  while (1) {
    if (tre[tre[nw].ls].siz + 1 == k) return nw;
    if (tre[tre[nw].ls].siz + 1 < k)
      nw = tre[nw].rs, k -= tre[tre[nw].ls].siz + 1;
    else
      nw = tre[nw].ls;
  }
}
int nxt(int val) {
  int rx, ry;
  splitval(root, rx, ry, val - 1);
  int res = findkth(ry, 1);
  root = merge(rx, ry);
  return res;
}
void del(int val) {
  int rx, ry, rz;
  splitval(root, rx, rz, val);
  splitval(rx, rx, ry, val - 1);
  root = merge(merge(merge(rx, tre[ry].ls), tre[ry].rs), rz);
}
int main() {
  srand(time(0));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    if (i == 1) {
      ins(l);
      continue;
    }
    int qwq = nxt(r);
    int rx, ry, rz;
    splitval(root, rx, rz, r - 1);
    splitval(rx, rx, ry, l - 2);
    tre[ry].val++;
    tre[ry].tag++;
    root = merge(merge(rx, ry), rz);
    if (qwq) del(tre[qwq].val);
    ins(l);
  }
  printf("%d", tre[root].siz);
  return 0;
}
