#include <bits/stdc++.h>
using namespace std;
const pair<int, int> DD[] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                             {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
template <class T>
T smin(T &a, T b) {
  if (a > b) a = b;
  return a;
}
template <class T>
T smax(T &a, T b) {
  if (a < b) a = b;
  return a;
}
struct Tr {
  Tr *l, *r;
  int pr, v, lazy;
  Tr(void) {
    lazy = 0;
    l = r = 0;
    pr = rand();
    v = 0;
  }
  Tr(Tr *L, Tr *R, int vv) {
    lazy = 0;
    l = L;
    r = R;
    pr = rand();
    v = vv;
  }
  void lz(void) {
    v += lazy;
    if (l) l->lazy += lazy;
    if (r) r->lazy += lazy;
    lazy = 0;
  }
};
typedef Tr *tr;
int Answer(tr &Root) {
  if (!Root) return 0;
  Root->lz();
  return 1 + Answer(Root->l) + Answer(Root->r);
}
tr Merge(tr a, tr b) {
  if (a) a->lz();
  if (b) b->lz();
  if (!a) return b;
  if (!b) return a;
  if (a->pr > b->pr) {
    a->r = Merge(a->r, b);
    return a;
  } else {
    b->l = Merge(a, b->l);
    return b;
  }
}
void Split(tr Root, int k, tr &L, tr &R) {
  if (Root)
    Root->lz();
  else
    return void(L = R = 0);
  if (Root->v <= k)
    Split(Root->r, k, Root->r, R), L = Root;
  else
    Split(Root->l, k, L, Root->l), R = Root;
}
void Del(tr &Root, int k) {
  if (!Root) return;
  Root->lz();
  if (Root->v == k)
    Root = Merge(Root->l, Root->r);
  else if (Root->v < k)
    Del(Root->r, k);
  else
    Del(Root->l, k);
}
const int oo = 2e9;
int Bigger(tr &Root, int k) {
  if (!Root) return oo;
  Root->lz();
  if (Root->v >= k)
    return min(Root->v, Bigger(Root->l, k));
  else
    return Bigger(Root->r, k);
}
tr Root = new Tr(0, 0, 0);
void print(tr &Root) {
  if (!Root) return;
  Root->lz();
  print(Root->l);
  cerr << Root->v << ' ';
  print(Root->r);
}
void pp(tr &Root) {
  print(Root);
  cerr << '\n';
}
void update(int L, int R) {
  tr Left, mid, shit, Right;
  Split(Root, L - 1, Left, shit);
  Split(shit, R - 1, mid, Right);
  int big = Bigger(Right, R);
  if (big != oo) Del(Right, big);
  if (mid) mid->lazy += 1;
  Root = Merge(Left, Merge(new Tr(0, 0, L), Merge(mid, Right)));
}
int main(void) {
  srand(time(0));
  cout << fixed << setprecision(7);
  cerr << fixed << setprecision(7);
  int n;
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  while (n--) {
    int l, r;
    cin >> l >> r;
    update(l, r);
  }
  cout << Answer(Root) - 1 << '\n';
  cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms"
       << '\n';
  return 0;
}
