#include <bits/stdc++.h>
using namespace std;
int ch[5000011][2], fa[5000011], n, root, pos, siz = 2, L[5000011], R[5000011],
                                               ans, cnt;
stack<int> Stack;
struct node {
  int val, sum, flag;
} tree[5000011];
void push_up(int now) {
  int l = ch[now][0], r = ch[now][1];
  tree[now].sum = tree[l].sum + tree[r].sum + 1;
}
void push_down(int now) {
  int l = ch[now][0], r = ch[now][1];
  tree[l].val += tree[now].flag;
  tree[l].flag += tree[now].flag;
  tree[r].val += tree[now].flag;
  tree[r].flag += tree[now].flag;
  tree[now].flag = 0;
}
void all_push_down(int now) {
  if (!now) return;
  all_push_down(fa[now]);
  push_down(now);
}
void rotate(int x) {
  int f = fa[x], k = (ch[fa[x]][1] == x);
  ch[f][k] = ch[x][!k];
  ch[x][!k] = f;
  ch[fa[f]][(ch[fa[f]][1] == f)] = x;
  fa[x] = fa[f];
  fa[ch[f][k]] = f;
  fa[f] = x;
  push_up(f);
  push_up(x);
}
void splay(int x, int p) {
  all_push_down(x);
  while (fa[x] != p) {
    int f = fa[x];
    if (fa[f] == p) {
      rotate(x);
      break;
    }
    if ((ch[fa[x]][1] == x) ^ (ch[fa[f]][1] == f))
      rotate(x);
    else
      rotate(f);
    rotate(x);
  }
  if (p == 0) root = x;
}
void get_last_smaller(int now, int x) {
  if (!now) return;
  cnt++;
  push_down(now);
  if (tree[now].val < x) {
    pos = now;
    get_last_smaller(ch[now][1], x);
  } else
    get_last_smaller(ch[now][0], x);
}
void get_first_bigger(int now, int x) {
  if (!now) return;
  push_down(now);
  if (tree[now].val > x) {
    pos = now;
    get_first_bigger(ch[now][0], x);
  } else
    get_first_bigger(ch[now][1], x);
}
void print(int now) {
  if (!now) return;
  print(ch[now][0]);
  printf("%d ", tree[now].val);
  print(ch[now][1]);
}
void solve(int l, int r) {
  cnt = 0;
  int a, b, c;
  get_first_bigger(root, r - 1);
  c = pos;
  if (tree[c].val != 0x7f7f7f7f) {
    get_first_bigger(root, tree[c].val);
    a = pos;
    get_last_smaller(root, tree[c].val);
    b = pos;
    splay(b, 0);
    splay(a, root);
    Stack.push(ch[a][0]);
    ch[a][0] = 0;
    push_up(a);
    push_up(b);
    ans--;
  }
  get_first_bigger(root, l - 1);
  a = pos;
  get_last_smaller(root, tree[a].val);
  a = pos;
  get_last_smaller(root, r);
  b = pos;
  get_first_bigger(root, tree[b].val);
  b = pos;
  splay(a, 0);
  splay(b, root);
  tree[ch[b][0]].flag++;
  tree[ch[b][0]].val++;
  get_last_smaller(root, l);
  a = pos;
  get_first_bigger(root, tree[a].val);
  b = pos;
  splay(a, 0);
  splay(b, root);
  if (Stack.empty())
    c = ++siz;
  else
    c = Stack.top(), Stack.pop(), memset(&tree[c], 0, sizeof(tree[c]));
  ch[c][0] = ch[c][1] = fa[c] = 0;
  tree[c].sum = 1;
  tree[c].val = l;
  fa[c] = b;
  ans++;
  ch[b][0] = c;
  push_up(b);
  push_up(a);
  get_last_smaller(root, 0x7f7f7f7f);
  splay(pos, 0);
}
int main() {
  scanf("%d", &n);
  root = 1;
  ch[root][1] = 2;
  tree[root].val = -0x7f7f7f7f;
  tree[2].val = 0x7f7f7f7f;
  tree[root].sum = 2;
  tree[2].sum = 1;
  fa[2] = root;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &L[i], &R[i]);
    solve(L[i], R[i]);
  }
  printf("%d", ans);
  return 0;
}
