#include <bits/stdc++.h>
const int maxn = 1.4e6 + 17;
const int inf = 1e9 + 17;
int n, val[maxn], prior[maxn], tag[maxn], ch[maxn][2], l[maxn], r[maxn], tl, rt,
    L, M, R;
int newnode(int x) {
  prior[++tl] = rand() * 32768 + rand();
  val[tl] = x;
  tag[tl] = ch[tl][0] = ch[tl][1] = 0;
  return tl;
}
void give_tag(int x, int y) {
  tag[x] += y;
  val[x] += y;
}
void pushdown(int x) {
  if (ch[x][0]) give_tag(ch[x][0], tag[x]);
  if (ch[x][1]) give_tag(ch[x][1], tag[x]);
  tag[x] = 0;
}
int find_first(int x) {
  pushdown(x);
  if (!ch[x][0]) return val[x];
  return find_first(ch[x][0]);
}
int find(int rt) {
  if (!rt) return 0;
  pushdown(rt);
  return find(ch[rt][0]) + find(ch[rt][1]) + (val[rt] < inf ? 1 : 0);
}
void merge(int &t, int l, int r) {
  if (!l) {
    t = r;
    return;
  }
  if (!r) {
    t = l;
    return;
  }
  pushdown(l);
  pushdown(r);
  if (prior[l] > prior[r]) {
    merge(ch[l][1], ch[l][1], r);
    t = l;
    return;
  }
  merge(ch[r][0], l, ch[r][0]);
  t = r;
}
void split(int t, int v, int &l, int &r) {
  if (!t) {
    l = r = 0;
    return;
  }
  pushdown(t);
  if (val[t] >= v) {
    split(ch[t][0], v, l, ch[t][0]);
    r = t;
  } else {
    split(ch[t][1], v, ch[t][1], r);
    l = t;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &l[i], &r[i]);
  rt = newnode(0);
  for (int i = 1; i <= n; ++i) merge(rt, rt, newnode(inf + i));
  for (int i = 1; i <= n; ++i) {
    split(rt, l[i], L, R);
    split(R, r[i], M, R);
    if (M) give_tag(M, 1);
    int c = find_first(R), d;
    split(R, c + 1, d, R);
    merge(rt, L, newnode(l[i]));
    merge(rt, rt, M);
    merge(rt, rt, R);
  }
  printf("%d", find(rt) - 1);
  return 0;
}
