#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct Treap {
  struct node {
    int key, prior, cnt, lazy;
    node *l, *r;
    node() {}
    node(int key) : key(key), prior(rng()), cnt(1), lazy(0), l(0), r(0) {}
  };
  typedef node *pnode;
  void _lazy(pnode t) {
    if (!t) return;
    t->key += t->lazy;
    if (t->l) t->l->lazy += t->lazy;
    if (t->r) t->r->lazy += t->lazy;
    t->lazy = 0;
  }
  int cnt(pnode t) { return t ? t->cnt : 0; }
  void recal(pnode t) {
    _lazy(t);
    if (t) t->cnt = 1 + cnt(t->l) + cnt(t->r);
  }
  void split(pnode t, pnode &l, pnode &r, int key) {
    _lazy(t);
    if (!t) return void(l = r = 0);
    if (key < t->key)
      split(t->l, l, t->l, key), r = t;
    else
      split(t->r, t->r, r, key), l = t;
    recal(t);
  }
  void splitIm(pnode t, pnode &l, pnode &r, int key, int carry = 0) {
    _lazy(t);
    if (!t) return void(l = r = 0);
    int cur_key = carry + cnt(t->l);
    if (key < cur_key)
      splitIm(t->l, l, t->l, key, carry), r = t;
    else
      splitIm(t->r, t->r, r, key, carry + 1 + cnt(t->l)), l = t;
    recal(t);
  }
  void merge(pnode &t, pnode l, pnode r) {
    _lazy(t);
    if (!l || !r)
      t = l ? l : r;
    else if (l->prior > r->prior)
      merge(l->r, l->r, r), t = l;
    else
      merge(r->l, l, r->l), t = r;
    recal(t);
  }
  pnode root;
  Treap() : root(0) {}
  void insert(int key) {
    pnode l, k, r;
    split(root, l, r, key);
    split(l, l, k, key - 1);
    k = new node(key);
    merge(root, l, k);
    merge(root, root, r);
  }
  void insertIm(int pos, int key) {
    pnode l, k, r;
    splitIm(root, l, r, pos - 1);
    k = new node(key);
    merge(root, l, k);
    merge(root, root, r);
  }
  void erase(int key) {
    pnode l, k, r;
    split(root, l, k, key - 1);
    split(k, k, r, key);
    delete k;
    merge(root, l, r);
  }
  void get(int u, int v) {
    pnode l, k, r;
    split(root, l, k, u - 1);
    split(k, k, r, v);
    merge(root, l, k);
    merge(root, root, r);
    return;
  }
  int lower_bound(int key) {
    pnode l, r;
    split(root, l, r, key - 1);
    int res = cnt(l);
    merge(root, l, r);
    return res;
  }
  void upd(int u, int v) {
    pnode l, k, ohno, r;
    int U = lower_bound(u);
    int V = lower_bound(v) - 1;
    splitIm(root, l, k, U - 1);
    splitIm(k, k, ohno, V - U);
    splitIm(ohno, ohno, r, 0);
    if (k) k->lazy += 1, _lazy(k);
    ohno = new node(u);
    merge(root, l, ohno);
    merge(k, k, r);
    merge(root, root, k);
  }
  void print(pnode t) {
    if (!t) return;
    print(t->l);
    cout << t->key << endl;
    print(t->r);
  }
};
void ngk() {
  int n;
  cin >> n;
  Treap dp;
  dp.insertIm(0, 0);
  while (n--) {
    int l, r;
    cin >> l >> r;
    dp.upd(l, r);
  }
  cout << dp.cnt(dp.root) - 1;
}
int main(int argc, char *argv[]) {
  iostream::sync_with_stdio(0);
  int test = 1;
  while (test--) {
    ngk();
  }
  return 0;
}
