#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
mt19937 rng(114514);
struct N;
using NP = N*;
struct N {
  static NP last;
  NP l, r;
  int v, lz, sz;
  int P;
  N() {
    sz = 0;
    v = -1;
    l = r = this;
  }
  N(int _v) : v(_v) {
    lz = 0;
    sz = 1;
    l = r = last;
    P = rng();
  }
  void apply(int d) {
    if (!sz) return;
    v += d;
    lz += d;
  }
  void push() {
    l->apply(lz);
    r->apply(lz);
    lz = 0;
  }
  int get(int a) {
    if (!sz) return 0;
    push();
    if (v < a) return 1 + l->sz + r->get(a);
    return l->get(a);
  }
  int right() {
    if (!r->sz) return v;
    push();
    return r->right();
  }
  void debug() {
    if (!sz) return;
    push();
    l->debug();
    cerr << v << " ";
    r->debug();
  }
  NP update() {
    sz = 1 + l->sz + r->sz;
    return this;
  }
};
NP N::last = new N();
NP last = N::last;
pair<NP, NP> split(NP x, int k) {
  if (!x->sz) return {last, last};
  x->push();
  if (k <= x->l->sz) {
    auto y = split(x->l, k);
    x->l = y.second;
    y.second = x->update();
    return y;
  } else {
    auto y = split(x->r, k - 1 - x->l->sz);
    x->r = y.first;
    y.first = x->update();
    return y;
  }
}
NP merge(NP l, NP r) {
  if (!l->sz) return r;
  if (!r->sz) return l;
  if (l->P < r->P) {
    l->push();
    l->r = merge(l->r, r);
    return l->update();
  } else {
    r->push();
    r->l = merge(l, r->l);
    return r->update();
  }
}
int n;
NP t0 = last, t1 = last, t2 = last;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    int a = t0->get(l);
    tie(t0, t1) = split(t0, a);
    int b = t1->get(r);
    tie(t1, t2) = split(t1, b + 1);
    if (t1->sz > b) {
      t1 = split(t1, b).first;
    }
    t1->apply(1);
    t1 = merge(new N(l), t1);
    t0 = merge(t0, merge(t1, t2));
  }
  cout << t0->sz << "\n";
  return 0;
}
