#include <bits/stdc++.h>
using namespace std;
const int MAXN = (1 << 20);
struct node {
  int lazy, sz, mx, val, prior, value;
  node *l, *r;
  node() {
    lazy = 0;
    value = 0;
    sz = 0;
    mx = 0;
    val = 0;
    prior = 0;
    l = nullptr;
    r = nullptr;
  }
  node(int v, int _val) {
    lazy = 0;
    value = v;
    val = _val;
    mx = val;
    sz = 1;
    prior = rand();
    l = nullptr;
    r = nullptr;
  }
};
typedef node *pnode;
int size(pnode v) { return v ? v->sz : 0; }
void update_size(pnode &v) {
  if (v) v->sz = size(v->l) + size(v->r) + 1;
}
void reset(pnode &v) {
  if (v) v->mx = v->val;
}
void combine(pnode &v, pnode l, pnode r) {
  if (!l) {
    v = r;
    return;
  }
  if (!r) {
    v = l;
    return;
  }
  v->mx = max(l->mx, r->mx);
}
void push(pnode &v) {
  if (!v) return;
  v->value += v->lazy;
  v->val += v->lazy;
  v->mx += v->lazy;
  if (v->l) v->l->lazy += v->lazy;
  if (v->r) v->r->lazy += v->lazy;
  v->lazy = 0;
}
void operation(pnode &v) {
  if (!v) return;
  push(v->l);
  push(v->r);
  reset(v);
  combine(v, v->l, v);
  combine(v, v, v->r);
}
void merge(pnode &t, pnode l, pnode r) {
  push(l);
  push(r);
  if (!l) {
    t = r;
    return;
  }
  if (!r) {
    t = l;
    return;
  }
  if (l->prior > r->prior)
    merge(l->r, l->r, r), t = l;
  else
    merge(r->l, l, r->l), t = r;
  update_size(t);
  operation(t);
}
void split(pnode t, pnode &l, pnode &r, int k) {
  push(t);
  if (!t) {
    l = nullptr;
    r = nullptr;
    return;
  }
  if (t->value <= k)
    split(t->r, t->r, r, k), l = t;
  else
    split(t->l, l, t->l, k), r = t;
  update_size(t);
  operation(t);
}
void split_sz(pnode t, pnode &l, pnode &r, int k, int add = 0) {
  if (!t) {
    l = nullptr;
    r = nullptr;
    return;
  }
  int idx = add + size(t->l);
  if (idx <= k)
    split_sz(t->r, t->r, r, k, idx + 1), l = t;
  else
    split_sz(t->l, l, t->l, k, add), r = t;
  update_size(t);
  operation(t);
}
int l_ans(pnode &t) {
  push(t);
  if (!t->l)
    return t->val;
  else
    return l_ans(t->l);
}
int r_ans(pnode &t) {
  push(t);
  if (!t->r)
    return t->val;
  else
    return r_ans(t->r);
}
int n;
int L[MAXN], R[MAXN];
void read() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> L[i] >> R[i];
}
pnode t;
void solve() {
  t = new node(-2, 0);
  for (int i = 0; i < n; i++) {
    pnode l, r, mid;
    split(t, l, r, L[i] - 1);
    split(r, mid, r, R[i] - 1);
    pnode nw = new node(L[i], l->mx + 1);
    if (mid) {
      mid->lazy++;
      push(mid);
    }
    while (mid && r && r_ans(mid) >= l_ans(r)) {
      pnode tmp;
      split_sz(r, tmp, r, 0);
    }
    merge(l, l, nw);
    merge(l, l, mid);
    merge(t, l, r);
  }
  cout << t->mx << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
  return 0;
}
