#include <bits/stdc++.h>
using namespace std;
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long long MXLL = 4e18;
const int Sz = 1110111;
inline void Read_rap() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
inline void randomizer3000() {
  unsigned int seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
}
void files(string problem) {
  if (fopen((problem + ".in").c_str(), "r")) {
    freopen((problem + ".in").c_str(), "r", stdin);
    freopen((problem + ".out").c_str(), "w", stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen(in, "r"))
    freopen(in, "r", stdin);
  else
    cerr << "Warning: Input file not found" << endl;
}
struct treap {
  struct node {
    node *l, *r;
    int x, y;
    int sz;
    int add;
    node(int _x) {
      x = _x;
      y = rand();
      sz = 1, add = 0;
      l = r = NULL;
    }
    void push() {
      if (!this || !add) return;
      if (l) l->add += add;
      if (r) r->add += add;
      x += add;
      add = 0;
    }
    void recalc() {
      if (!this) return;
      sz = 1;
      if (l) sz += l->sz;
      if (r) sz += r->sz;
    }
  };
  node *T = NULL;
  treap() { srand(149); }
  void merge(node *&T, node *L, node *R) {
    if (!L) {
      T = R;
      return;
    }
    if (!R) {
      T = L;
      return;
    }
    L->push(), R->push();
    if (L->y > R->y) {
      merge(L->r, L->r, R);
      T = L;
    } else {
      merge(R->l, L, R->l);
      T = R;
    }
    T->recalc();
  }
  int getLeft(node *T) {
    T->push();
    if (!T->l) return T->x;
    return getLeft(T->l);
  }
  void split(node *T, int x, node *&L, node *&R) {
    if (!T) {
      L = R = NULL;
      return;
    }
    T->push();
    if (T->x < x) {
      split(T->r, x, T->r, R);
      L = T;
      L->recalc();
    } else {
      split(T->l, x, L, T->l);
      R = T;
      R->recalc();
    }
  }
  void update(int l, int r) {
    node *L, *R, *M;
    L = R = M = NULL;
    split(T, l, L, R);
    split(R, r, M, R);
    node *todel = NULL;
    if (R) split(R, getLeft(R) + 1, todel, R);
    if (M) {
      M->add = 1;
    }
    merge(T, L, new node(l));
    merge(T, T, M);
    merge(T, T, R);
  }
  int getsize() { return T->sz; }
  void show(node *T) {
    if (!T) return;
    T->push();
    show(T->l);
    cout << T->x << ' ';
    show(T->r);
  }
};
int main() {
  Read_rap();
  int n;
  cin >> n;
  treap T;
  for (int i = 1; i <= n; i++) {
    int l, r;
    cin >> l >> r;
    T.update(l, r);
  }
  cout << T.getsize();
  return 0;
}
