#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
int n, l[maxn], r[maxn];
struct node {
  int rnd, v, lzy, siz, ch[2];
} s[maxn];
int tot, root;
inline int gi() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int sum = 0;
  while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
  return sum;
}
inline int new_node(int v) { return s[++tot] = (node){rand(), v, 0, 1}, tot; }
inline void update(int x) {
  s[x].siz = s[s[x].ch[0]].siz + s[s[x].ch[1]].siz + 1;
}
inline void pushdown(int x) {
  if (!s[x].lzy) return;
  s[s[x].ch[0]].v += s[x].lzy;
  s[s[x].ch[0]].lzy += s[x].lzy;
  s[s[x].ch[1]].v += s[x].lzy;
  s[s[x].ch[1]].lzy += s[x].lzy;
  s[x].lzy = 0;
}
int merge(int x, int y) {
  if (!x || !y) return x | y;
  pushdown(x);
  pushdown(y);
  if (s[x].rnd < s[y].rnd)
    return s[x].ch[1] = merge(s[x].ch[1], y), update(x), x;
  else
    return s[y].ch[0] = merge(x, s[y].ch[0]), update(y), y;
}
void split1(int r, int k, int &x, int &y) {
  if (!r) return x = y = 0, void();
  pushdown(r);
  if (s[r].v <= k)
    x = r, split1(s[r].ch[1], k, s[r].ch[1], y);
  else
    y = r, split1(s[r].ch[0], k, x, s[r].ch[0]);
  update(r);
}
void split2(int r, int k, int &x, int &y) {
  if (!r) return x = y = 0, void();
  pushdown(r);
  if (k <= s[s[r].ch[0]].siz)
    y = r, split2(s[r].ch[0], k, x, s[r].ch[0]);
  else
    x = r, split2(s[r].ch[1], k - s[s[r].ch[0]].siz - 1, s[r].ch[1], y);
  update(r);
}
void dfs(int x) {
  pushdown(x);
  if (s[x].ch[0]) dfs(s[x].ch[0]);
  printf("%d ", s[x].v);
  if (s[x].ch[1]) dfs(s[x].ch[1]);
}
int main() {
  n = gi();
  for (int i = 1; i <= n; ++i) l[i] = gi(), r[i] = gi();
  for (int x, y, a, b, c, d, i = 1; i <= n; ++i) {
    split1(root, l[i] - 1, x, y);
    split1(y, r[i] - 1, a, b);
    ++s[a].v;
    ++s[a].lzy;
    split2(b, 1, c, d);
    root = merge(x, merge(new_node(l[i]), merge(a, d)));
  }
  printf("%d\n", s[root].siz);
  return 0;
}
