#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a * (b / gcd(a, b));
}
int n, ll[500005], rr[500005];
struct node {
  int prior, size, dp, lazyAdd;
  struct node *l, *r;
};
typedef struct node *Node;
Node treap = NULL, L = NULL, R = NULL, M = NULL, temp = NULL;
void lazy(Node t) {
  if (!t || !t->lazyAdd) return;
  t->dp += t->lazyAdd;
  if (t->l) t->l->lazyAdd += t->lazyAdd;
  if (t->r) t->r->lazyAdd += t->lazyAdd;
  t->lazyAdd = 0;
}
void split(Node t, Node &less, Node &grt, int key) {
  if (!t) return void(less = grt = NULL);
  lazy(t);
  if (t->dp < key)
    split(t->r, t->r, grt, key), less = t;
  else
    split(t->l, less, t->l, key), grt = t;
}
void merge(Node &t, Node l, Node r) {
  lazy(l);
  lazy(r);
  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;
}
int findBegin(Node t) {
  lazy(t);
  if (!t->l) return t->dp;
  return findBegin(t->l);
}
int findmax(Node t) {
  if (!t) return 0;
  lazy(t);
  return findmax(t->l) + findmax(t->r) + (t->dp <= (int)(1e9) ? 1 : 0);
}
Node init(int val) {
  Node x = new node();
  x->l = x->r = NULL;
  x->prior = rand();
  x->size = 1;
  x->dp = val;
  return x;
}
void print(Node t) {
  if (t) {
    lazy(t);
    print(t->l);
    cout << t->dp << " ";
    print(t->r);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  merge(treap, treap, init(0));
  for (int i = 0; i < n; i++) {
    cin >> ll[i] >> rr[i];
    merge(treap, treap, init((int)(1e9) + i + 5));
  }
  for (int i = 0; i < n; i++) {
    split(treap, L, R, ll[i]);
    split(R, M, R, rr[i]);
    if (M) M->lazyAdd += 1;
    int cnt = findBegin(R);
    split(R, temp, R, cnt + 1);
    merge(treap, L, init(ll[i]));
    merge(treap, treap, M);
    merge(treap, treap, R);
  }
  cout << findmax(treap) - 1 << endl;
  return 0;
}
