#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
int n, tot, pre, nxt, ans, rt;
struct node {
  int ch[2], fa, tag, sv, siz;
} s[maxn << 2];
inline void pushup(int x) {
  s[x].siz = s[s[x].ch[0]].siz + s[s[x].ch[1]].siz + 1;
}
inline void upd(int x, int v) {
  if (x) s[x].tag += v, s[x].sv += v;
}
inline void pushdown(int x) {
  if (s[x].tag)
    upd(s[x].ch[0], s[x].tag), upd(s[x].ch[1], s[x].tag), s[x].tag = 0;
}
inline void rotate(int x, int &k) {
  int y = s[x].fa, z = s[y].fa, d = (x == s[y].ch[1]);
  if (y == k)
    k = x;
  else
    s[z].ch[y == s[z].ch[1]] = x;
  s[x].fa = z, s[y].fa = x, s[y].ch[d] = s[x].ch[d ^ 1];
  if (s[x].ch[d ^ 1]) s[s[x].ch[d ^ 1]].fa = y;
  s[x].ch[d ^ 1] = y;
  pushup(y), pushup(x);
}
inline void splay(int x, int &k) {
  while (x != k) {
    int y = s[x].fa, z = s[y].fa;
    if (y != k) {
      if ((x == s[y].ch[0]) ^ (y == s[z].ch[0]))
        rotate(x, k);
      else
        rotate(y, k);
    }
    rotate(x, k);
  }
}
int find(int x, int y) {
  pushdown(x);
  if (y <= s[s[x].ch[0]].siz)
    return find(s[x].ch[0], y);
  else if (y > s[s[x].ch[0]].siz + 1)
    return find(s[x].ch[1], y - s[s[x].ch[0]].siz - 1);
  return x;
}
void getpre(int x, int y) {
  if (!x) return;
  pushdown(x);
  if (s[x].sv < y)
    pre = x, getpre(s[x].ch[1], y);
  else
    getpre(s[x].ch[0], y);
}
int build(int l, int r) {
  if (l > r) return 0;
  int x = (l + r) >> 1;
  s[x].siz = r - l + 1, s[x].ch[0] = build(l, x - 1),
  s[x].ch[1] = build(x + 1, r), s[x].sv = 1 << 30;
  if (s[x].ch[0]) s[s[x].ch[0]].fa = x;
  if (s[x].ch[1]) s[s[x].ch[1]].fa = x;
  pushup(x);
  return x;
}
void dfs(int x, int y) {
  if (!x) return;
  pushdown(x);
  if (s[x].sv < (1 << 30)) {
    ans = max(ans, y + s[s[x].ch[0]].siz);
    dfs(s[x].ch[1], y + s[s[x].ch[0]].siz + 1);
  } else
    dfs(s[x].ch[0], y);
}
inline int rd() {
  int ret = 0, f = 1;
  char gc = getchar();
  while (gc < '0' || gc > '9') {
    if (gc == '-') f = -f;
    gc = getchar();
  }
  while (gc >= '0' && gc <= '9') ret = ret * 10 + (gc ^ '0'), gc = getchar();
  return ret * f;
}
int main() {
  n = rd();
  rt = build(1, n + 3);
  s[0].sv = s[1].sv = 0;
  int i, a, b, x, y, z, rx, ry, p, q;
  for (i = 1; i <= n; i++) {
    a = rd(), b = rd();
    getpre(rt, a), x = pre, getpre(rt, b), y = pre;
    splay(y, rt), ry = s[s[y].ch[0]].siz + 1;
    q = find(y, ry + 2), splay(q, s[y].ch[1]);
    z = s[q].ch[0], s[q].ch[0] = 0, pushup(q), pushup(y);
    s[z].sv = a;
    splay(x, rt), rx = s[s[x].ch[0]].siz + 1;
    p = find(x, rx + 1), splay(p, s[x].ch[1]);
    s[p].ch[0] = z, s[z].fa = p, pushup(p), pushup(x);
    splay(z, rt), splay(q, s[z].ch[1]);
    upd(s[q].ch[0], 1);
  }
  dfs(rt, 0);
  printf("%d", ans);
  return 0;
}
