#include <bits/stdc++.h>
using namespace std;
string itos(int x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
struct node {
  int pr, sz, val, add;
  node *l, *r;
  node(int x) {
    val = x;
    pr = (rand() << 15) | rand();
    l = r = NULL;
    add = 0;
  }
};
void push(node *T) {
  T->val += T->add;
  if (T->l) T->l->add += T->add;
  if (T->r) T->r->add += T->add;
  T->add = 0;
}
void merge(node *&T, node *L, node *R) {
  if (L == NULL) {
    T = R;
    return;
  }
  if (R == NULL) {
    T = L;
    return;
  }
  if (L->pr > R->pr) {
    push(L);
    merge(L->r, L->r, R);
    T = L;
    return;
  } else {
    push(R);
    merge(R->l, L, R->l);
    T = R;
    return;
  }
}
void split(node *T, int val, node *&L, node *&R) {
  if (T == NULL) {
    L = R = NULL;
    return;
  }
  push(T);
  if (T->val >= val) {
    R = T;
    split(T->l, val, L, T->l);
  } else {
    L = T;
    split(T->r, val, T->r, R);
  }
}
int frt(node *T) {
  push(T);
  if (T->l == NULL) return T->val;
  return frt(T->l);
}
int cnt(node *T) {
  if (T == NULL) return 0;
  push(T);
  return cnt(T->l) + cnt(T->r) + (T->val < 1000000007);
}
int n;
node *root = new node(0);
node *L, *R, *M, *tmp;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) merge(root, root, new node(1000000007 + i));
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    split(root, l, L, R);
    split(R, r, M, R);
    if (M != NULL) M->add++;
    split(R, frt(R) + 1, tmp, R);
    merge(root, L, new node(l));
    merge(root, root, M);
    merge(root, root, R);
  }
  cout << cnt(root) - 1 << endl;
  return 0;
}
