#include <bits/stdc++.h>
const int N = 500005, inf = 1000000007;
using namespace std;
int n, root, top_pool, pool[N], d[N];
struct poi {
  int l, r;
} a[N];
struct tnode {
  int l, r, fa, tag, val, pos;
} tr[N];
int new_node() { return pool[top_pool--]; }
void add_node(int x) { pool[++top_pool] = x; }
void psd(int p) {
  if (!p) return;
  int l = tr[p].l, r = tr[p].r;
  if (l) {
    tr[l].val += tr[p].tag, tr[l].pos += tr[p].tag;
    tr[l].tag += tr[p].tag;
  }
  if (r) {
    tr[r].val += tr[p].tag, tr[r].pos += tr[p].tag;
    tr[r].tag += tr[p].tag;
  }
  tr[p].tag = 0;
}
void rotate(int x) {
  int y = tr[x].fa, z = tr[y].fa;
  if (tr[z].l == y)
    tr[z].l = x;
  else
    tr[z].r = x;
  tr[x].fa = z;
  if (tr[y].l == x) {
    tr[y].l = tr[x].r, tr[tr[x].r].fa = y;
    tr[x].r = y, tr[y].fa = x;
  } else {
    tr[y].r = tr[x].l, tr[tr[x].l].fa = y;
    tr[x].l = y, tr[y].fa = x;
  }
  if (root == y) root = x;
}
void splay(int x, int t) {
  if (x == t) return;
  d[0] = 0;
  for (; x != t; x = tr[x].fa) d[++d[0]] = x;
  for (int i = d[0]; i; --i) psd(d[i]);
  x = d[1];
  for (; tr[x].fa != t && tr[tr[x].fa].fa != t;) {
    int y = tr[x].fa, z = tr[y].fa;
    if (!((tr[y].l == x) ^ (tr[z].l == y)))
      rotate(y), rotate(x);
    else
      rotate(x), rotate(x);
  }
  if (tr[x].fa != t) rotate(x);
}
void insert(int pos, int val) {
  int u = new_node();
  tr[u].pos = pos, tr[u].val = val;
  tr[u].l = tr[u].r = tr[u].fa = tr[u].tag = 0;
  if (!root) {
    root = u;
    return;
  }
  int p = root, las;
  for (; p;) {
    las = p;
    psd(p);
    if (pos < tr[p].pos)
      p = tr[p].l;
    else
      p = tr[p].r;
  }
  if (pos < tr[las].pos)
    tr[las].l = u;
  else
    tr[las].r = u;
  tr[u].fa = las;
  splay(u, 0);
}
int find(int p, int ave) {
  psd(p);
  if (!p) return 0;
  if (tr[p].val < ave) {
    int x = find(tr[p].r, ave);
    if (x)
      return x;
    else
      return tr[p].pos;
  } else
    return find(tr[p].l, ave);
}
int find_order(int p, int rank) {
  psd(p);
  if (!p) return 0;
  if (tr[p].pos == rank) return p;
  if (rank < tr[p].pos)
    return find_order(tr[p].l, rank);
  else
    return find_order(tr[p].r, rank);
}
void del(int rank_p) {
  int l = find_order(root, rank_p - 1), r = find_order(root, rank_p + 1);
  splay(l, 0), splay(r, l);
  int p = tr[r].l;
  tr[r].l = 0;
  add_node(p);
}
void modify(int l, int r) {
  if (l > r) return;
  int L = find_order(root, l - 1), R = find_order(root, r + 2);
  splay(L, 0), splay(R, L);
  int p = tr[R].l;
  ++tr[p].val, ++tr[p].pos, ++tr[p].tag;
  psd(p);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &a[i].l, &a[i].r);
  root = 0;
  top_pool = n + 6;
  for (int i = 1; i <= n + 6; ++i) pool[i] = i;
  insert(0, 0);
  for (int i = 1; i <= n + 5; ++i) insert(i, inf);
  for (int i = 1; i <= n; ++i) {
    int x = find(root, a[i].l), y = find(root, a[i].r);
    if (x > y) continue;
    del(y + 1);
    modify(x + 1, y);
    insert(x + 1, a[i].l);
  }
  int ans = find(root, inf);
  printf("%d\n", ans);
  return 0;
}
