#include <bits/stdc++.h>
using namespace std;
int x, y, n, r, f[300001];
int main() {
  scanf("%d", &n);
  while (n--) {
    scanf("%d%d", &x, &y);
    int* a = lower_bound(f + 1, f + r + 1, y);
    if (a - f > r) r++, f[r] = 2e9;
    for (; a-- > f && f + r - a < 4000;)
      if (*a >= x)
        *(a + 1) = *a + 1;
      else
        break;
    if (*a<x&&*(a + 1)> x) *(a + 1) = x;
  }
  cout << r;
  return 0;
}
