#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
int n, m;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}
inline void print(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
struct node {
  int l, r;
  node() {}
  node(int a, int b) { l = a, r = b; }
};
struct fhq_treap {
  int root, tot, size[600005], fix[600005], val[600005], tag[600005],
      mn[600005], ch[600005][2];
  void update(int x) {
    mn[x] = val[x], size[x] = 1;
    if (ch[x][0]) mn[x] = min(mn[x], mn[ch[x][0]]), size[x] += size[ch[x][0]];
    if (ch[x][1]) mn[x] = min(mn[x], mn[ch[x][1]]), size[x] += size[ch[x][1]];
  }
  int newnode(int v) {
    size[++tot] = 1, fix[tot] = rand(), mn[tot] = val[tot] = v;
    return tot;
  }
  void addtag(int x, int v) { val[x] += v, mn[x] += v, tag[x] += v; }
  void pushdown(int x) {
    if (!tag[x]) return;
    addtag(ch[x][0], tag[x]), addtag(ch[x][1], tag[x]), tag[x] = 0;
  }
  int merge(int x, int y) {
    if (!x) return y;
    if (!y) return x;
    pushdown(x), pushdown(y);
    if (fix[x] < fix[y])
      return ch[x][1] = merge(ch[x][1], y), update(x), x;
    else
      return ch[y][0] = merge(x, ch[y][0]), update(y), y;
  }
  node split(int x, int k) {
    if (!x) return node(0, 0);
    node y(0, 0);
    pushdown(x);
    if (size[ch[x][0]] >= k)
      y = split(ch[x][0], k), ch[x][0] = y.r, update(y.r = x);
    else
      y = split(ch[x][1], k - size[ch[x][0]] - 1), ch[x][1] = y.l,
      update(y.l = x);
    return y;
  }
  int find(int x, int k) {
    pushdown(x);
    if (ch[x][1] && mn[ch[x][1]] < k)
      return size[ch[x][0]] + 1 + find(ch[x][1], k);
    if (val[x] < k) return size[ch[x][0]] + 1;
    if (ch[x][0] && mn[ch[x][0]] < k) return find(ch[x][0], k);
    return 0;
  }
  void add(int l, int r) {
    if (l > r) return;
    node a = split(root, l - 1), b = split(a.r, r - l + 1);
    addtag(b.l, 1);
    root = merge(a.l, merge(b.l, b.r));
  }
  void del(int k) {
    node a = split(root, k - 1), b = split(a.r, 1);
    root = merge(a.l, b.r);
  }
  void ins(int k, int v) {
    node a = split(root, k - 1);
    root = merge(a.l, merge(newnode(v), a.r));
  }
  int get_ans(int x) {
    if (ch[x][1] && mn[ch[x][1]] < inf)
      return size[ch[x][0]] + 1 + get_ans(ch[x][1]);
    if (val[x] < inf) return size[ch[x][0]] + 1;
    return get_ans(ch[x][0]);
  }
  void print(int x) {
    pushdown(x);
    if (ch[x][0]) print(ch[x][0]);
    printf("%d ", val[x]);
    if (ch[x][1]) print(ch[x][1]);
  }
} T;
int main() {
  srand('f' + 'u' + 'c' + 'k' + 'p' + 'p' + 's');
  n = read();
  T.root = T.newnode(0);
  for (int i = 2; i <= n + 1; i++) T.root = T.merge(T.root, T.newnode(inf));
  for (int i = 1; i <= n; i++) {
    int l = read(), r = read(), x = T.find(T.root, l), y = T.find(T.root, r);
    T.add(x + 1, y), T.del(min(n + 1, y + 1)), T.ins(x + 1, l);
  }
  printf("%d\n", T.get_ans(T.root) - 1);
  return 0;
}
