#include <bits/stdc++.h>
using namespace std;
int n;
struct T {
  int l, r, rd, val, tag, size;
} t[200100 << 1];
int ncc[200100 << 1], nct;
int tot, root;
inline int newnode(int val) {
  int nownode;
  if (nct)
    nownode = ncc[nct--];
  else
    nownode = ++tot;
  t[nownode].l = t[nownode].r = 0;
  t[nownode].rd = rand();
  t[nownode].val = val;
  t[nownode].size = 1;
  t[nownode].tag = 0;
  return nownode;
}
inline void pushup(int p) { t[p].size = t[t[p].l].size + t[t[p].r].size + 1; }
inline void change(int p, int ad) {
  if (p) t[p].val += ad, t[p].tag += ad;
}
inline void pushdown(int p) {
  if (!p || !t[p].tag) return;
  change(t[p].l, t[p].tag);
  change(t[p].r, t[p].tag);
  t[p].tag = 0;
}
inline void split(int now, int &x, int &y, int k) {
  if (!now) {
    x = y = 0;
    return;
  }
  pushdown(now);
  if (t[now].val <= k) {
    x = now;
    split(t[now].r, t[x].r, y, k);
  } else {
    y = now;
    split(t[now].l, x, t[y].l, k);
  }
  pushup(now);
}
inline int merge(int x, int y) {
  if (!x || !y) return x + y;
  pushdown(x);
  pushdown(y);
  if (t[x].rd <= t[y].rd) {
    t[y].l = merge(x, t[y].l);
    pushup(y);
    return y;
  } else {
    t[x].r = merge(t[x].r, y);
    pushup(x);
    return x;
  }
}
inline int Kth(int now, int k) {
  if (t[now].size < k) return -1;
  if (!k) return -1;
  while (1) {
    if (t[t[now].l].size >= k)
      now = t[now].l;
    else if (t[t[now].l].size + 1 == k)
      return now;
    else
      k -= t[t[now].l].size + 1, now = t[now].r;
  }
}
inline int pre(int val) {
  int a, b;
  split(root, a, b, val - 1);
  int ret = Kth(a, t[a].size);
  root = merge(a, b);
  return ret;
}
inline int nxt(int val) {
  int a, b;
  split(root, a, b, val);
  int ret = Kth(b, 1);
  root = merge(a, b);
  return ret;
}
inline void insert(int val) {
  int a, b;
  split(root, a, b, val);
  root = merge(merge(a, newnode(val)), b);
}
inline void del(int val) {
  int a, b, c, d;
  split(root, a, b, val);
  split(a, c, d, val - 1);
  ncc[++nct] = d;
  d = merge(t[d].l, t[d].r);
  root = merge(merge(c, d), b);
}
inline void update(int l, int r) {
  int a, b, c, d;
  split(root, a, b, l - 1);
  split(b, c, d, r);
  change(c, 1);
  root = merge(merge(a, c), d);
}
int main() {
  srand((unsigned)time(NULL));
  scanf("%d", &n);
  for (register int i = 1; i <= n; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    if (i == 1) {
      insert(l);
      continue;
    }
    int al = pre(l), ar = nxt(r - 1);
    update(l, r - 1);
    if (ar != -1) del(t[ar].val);
    insert(l);
  }
  printf("%d", root ? t[root].size : 0);
  return 0;
}
