#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n;
typedef struct node *pnode;
struct node {
  int prior, dp, lazy;
  pnode L, R;
  node(int x) {
    prior = rand();
    dp = x;
    lazy = 0;
    L = R = NULL;
  }
};
void push(pnode T) {
  T->dp += T->lazy;
  if (T->L) T->L->lazy += T->lazy;
  if (T->R) T->R->lazy += T->lazy;
  T->lazy = 0;
}
void merge(pnode &T, pnode L, pnode R) {
  if (!L) {
    T = R;
    return;
  }
  if (!R) {
    T = L;
    return;
  }
  if (L->prior > R->prior) {
    push(L);
    merge(L->R, L->R, R);
    T = L;
    return;
  }
  push(R);
  merge(R->L, L, R->L);
  T = R;
}
void split(pnode T, pnode &L, pnode &R, int value) {
  if (!T) {
    L = R = NULL;
    return;
  }
  push(T);
  if (T->dp >= value) {
    split(T->L, L, T->L, value);
    R = T;
    return;
  }
  split(T->R, T->R, R, value);
  L = T;
}
int find(pnode T) {
  push(T);
  if (!T->L) return T->dp;
  return find(T->L);
}
int get(pnode T) {
  if (!T) return 0;
  push(T);
  return get(T->L) + get(T->R) + (T->dp < INF);
}
pnode T = new node(0);
int main() {
  srand(time(NULL));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) merge(T, T, new node(INF + i));
  for (int i = 1; i <= n; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    pnode L = NULL;
    pnode R = NULL;
    pnode M = NULL;
    pnode DEL = NULL;
    split(T, L, R, l);
    split(R, M, R, r);
    if (M) M->lazy += 1;
    int total = find(R);
    split(R, DEL, R, total + 1);
    merge(T, L, new node(l));
    merge(T, T, M);
    merge(T, T, R);
  }
  printf("%d\n", get(T) - 1);
  return 0;
}
