#include <bits/stdc++.h>
using namespace std;
int n, m, son[1000005][2], f[1000005], add[1000005], a[1000005], w[1000005], lw,
    rt, ans;
void TA(int t, int d) { a[t] += d, add[t] += d; }
bool op(int t) { return (son[f[t]][0]) == t ? 0 : 1; }
void push(int t) {
  if (!add[t]) return;
  TA((son[t][0]), add[t]);
  TA((son[t][1]), add[t]);
  add[t] = 0;
}
void rotate(int x) {
  int fa = f[x], ff = f[fa], s, k = 0;
  if ((son[fa][0]) == x) k = 1;
  s = son[x][k], f[x] = ff;
  f[fa] = x, son[x][k] = fa, f[s] = fa, son[fa][k ^ 1] = s;
  if ((son[ff][0]) == fa)
    son[ff][0] = x;
  else
    son[ff][1] = x;
  f[0] = son[0][0] = son[0][1] = 0;
}
void splay(int x, int o) {
  int i;
  lw = 0;
  for (i = x; i; i = f[i]) w[++lw] = i;
  for (i = lw; i >= 1; i--) push(w[i]);
  while ((i = f[x]) != o) {
    if (f[i] == o)
      rotate(x);
    else if (op(i) ^ op(x))
      rotate(x), rotate(x);
    else
      rotate(i), rotate(x);
  }
  if (!o) rt = x;
}
int upper(int x) {
  int i = rt, y = 0;
  while (i) {
    push(i);
    if (a[i] < x)
      i = (son[i][1]);
    else
      y = i, i = (son[i][0]);
  }
  splay(y, 0);
  return y;
}
int lower(int x) {
  int i = rt, y = 0;
  while (i) {
    push(i);
    if (a[i] >= x)
      i = (son[i][0]);
    else
      y = i, i = (son[i][1]);
  }
  splay(y, 0);
  return y;
}
void Ins(int l, int r) {
  int p, u = l, q;
  l = upper(l), p = lower(r), r = upper(r);
  if (l == 1) {
    q = upper(a[p] + 1), splay(q, 0), splay(p, rt);
    push(p), son[p][1] = ++n, a[n] = u, f[n] = p;
    ans++, splay(n, 0);
    return;
  }
  if (r != 1) {
    q = upper(a[r] + 1);
    splay(q, 0), splay(p, rt);
    son[p][1] = f[(son[p][1])] = 0;
    r = q, ans--;
  }
  q = lower(a[l]), p = upper(a[l]);
  splay(p, 0), splay(q, rt);
  push(q), son[q][1] = ++n, a[n] = u, f[n] = q;
  splay(r, 0), splay(n, rt);
  ans++, TA((son[n][1]), 1);
}
int main() {
  int l, r;
  scanf("%d", &m);
  a[rt = n = 1] = +(1 << 30);
  a[rt = n = 2] = -(1 << 30);
  f[1] = 2, son[2][1] = 1;
  while (m--) {
    scanf("%d %d", &l, &r);
    Ins(l, r);
  }
  cout << ans;
  return 0;
}
