#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300010;
const int INF = 1e9 + 5;
int n;
int rt, fa[MAXN], son[MAXN][2], siz[MAXN], lazy[MAXN], val[MAXN];
void update(int o) { siz[o] = siz[son[o][0]] + siz[son[o][1]] + 1; }
int build(int l, int r, int f) {
  if (l == r) {
    fa[l] = f, siz[l] = 1;
    return l;
  }
  int o = (l + r) >> 1;
  fa[o] = f;
  son[o][0] = l < o ? build(l, o - 1, o) : 0;
  son[o][1] = r > o ? build(o + 1, r, o) : 0;
  update(o);
  return o;
}
void pushdown(int o) {
  val[son[o][0]] += lazy[o], lazy[son[o][0]] += lazy[o];
  val[son[o][1]] += lazy[o], lazy[son[o][1]] += lazy[o];
  lazy[o] = 0;
}
int find_v(int v) {
  int p = rt, res = 0;
  while (p) {
    if (lazy[p]) pushdown(p);
    if (val[p] <= v)
      res += siz[son[p][0]] + 1, p = son[p][1];
    else
      p = son[p][0];
  }
  return res - 1;
}
int find_p(int k) {
  int p = rt;
  while (p) {
    if (lazy[p]) pushdown(p);
    if (siz[son[p][0]] + 1 == k) return p;
    if (k > siz[son[p][0]] + 1)
      k -= siz[son[p][0]] + 1, p = son[p][1];
    else
      p = son[p][0];
  }
  return 0;
}
void rotate(int o, int &to) {
  int f = fa[o], ff = fa[f];
  int l = son[f][1] == o, r = l ^ 1;
  if (f == to)
    to = o;
  else
    son[ff][son[ff][1] == f] = o;
  fa[o] = ff, fa[f] = o, fa[son[o][r]] = f;
  son[f][l] = son[o][r], son[o][r] = f;
  update(f), update(o);
}
void splay(int o, int &to) {
  while (o != to) {
    int f = fa[o], ff = fa[f];
    if (f != to) rotate(((son[ff][0] == f) ^ (son[f][0] == o)) ? o : f, to);
    rotate(o, to);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 3; i <= n + 2; i++) val[i] = INF;
  val[1] = -INF, val[n + 3] = INF + 10;
  rt = build(1, n + 3, 0);
  for (int t = 1, l, r, x, y, k; t <= n; t++) {
    scanf("%d %d", &l, &r);
    x = find_v(l - 1), y = find_v(r - 1);
    if (x < y) {
      splay(find_p(y + 1), rt), splay(find_p(y + 3), son[rt][1]);
      k = son[son[rt][1]][0], fa[k] = 0, son[son[rt][1]][0] = 0;
      update(son[rt][1]), update(rt);
      splay(find_p(x + 1), rt), splay(find_p(x + 2), son[rt][1]);
      son[son[rt][1]][0] = k, fa[k] = son[rt][1];
      update(son[rt][1]), update(rt);
      splay(find_p(x + 2), rt), splay(find_p(y + 3), son[rt][1]);
      val[son[son[rt][1]][0]]++, lazy[son[son[rt][1]][0]]++;
    }
    splay(find_p(x + 1), rt), splay(find_p(x + 3), son[rt][1]);
    val[son[son[rt][1]][0]] = l;
  }
  printf("%d", find_v(INF - 1) - 1);
  return 0;
}
