#include <bits/stdc++.h>
using namespace std;
struct node {
  node *l, *r;
  int f, x, d;
  node(int _f = 0) {
    x = (rand() << 15) | rand();
    f = _f;
    d = 0;
    l = r = NULL;
  }
};
node *T, *L, *M, *R, *rub;
int n, l[300002], r[300002];
void push(node* T) {
  T->f += T->d;
  if (T->l != NULL) T->l->d += T->d;
  if (T->r != NULL) T->r->d += T->d;
  T->d = 0;
}
void merge(node*& T, node* L, node* R) {
  if (!L) {
    T = R;
    return;
  }
  if (!R) {
    T = L;
    return;
  }
  if (L->x < R->x) {
    push(L);
    merge(L->r, L->r, R);
    T = L;
    return;
  }
  push(R);
  merge(R->l, L, R->l);
  T = R;
}
void split(node* T, int val, node*& L, node*& R) {
  if (T == NULL) {
    L = R = NULL;
    return;
  }
  push(T);
  if (T->f >= val) {
    split(T->l, val, L, T->l);
    R = T;
    return;
  }
  split(T->r, val, T->r, R);
  L = T;
}
int find(node* T) {
  if (T == NULL) return 0;
  push(T);
  if (T->l == NULL) return T->f;
  return find(T->l);
}
int answer(node* T) {
  if (T == NULL) return 0;
  push(T);
  return answer(T->l) + answer(T->r) + 1;
}
int main() {
  srand((int)time(0));
  scanf("%d\n", &n);
  T = new node();
  int cnt;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d\n", l + i, r + i);
    split(T, l[i], L, R);
    split(R, r[i], M, R);
    if (M != NULL) M->d++;
    cnt = find(R);
    split(R, cnt + 1, rub, R);
    merge(T, L, new node(l[i]));
    merge(T, T, M);
    merge(T, T, R);
  }
  printf("%d", answer(T) - 1);
  return 0;
}
