#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
const int N = 6e5 + 10, INF = 1e9 + 10;
struct Tree {
  int son[2], fa, val, lazy;
} a[N];
int i, j, k, m, n, s, t, ans = -1, root, top;
int st[N];
void push_down(int rt) {
  int s0 = a[rt].son[0], s1 = a[rt].son[1];
  a[s0].val += a[rt].lazy, a[s0].lazy += a[rt].lazy;
  a[s1].val += a[rt].lazy, a[s1].lazy += a[rt].lazy;
  a[rt].lazy = 0;
}
void xz(int x) {
  int f = a[x].fa, o = a[f].son[1] == x, b = a[x].son[o ^ 1];
  a[x].fa = a[f].fa, a[f].fa = x, a[b].fa = f;
  a[x].son[o ^ 1] = f, a[f].son[o] = b,
               a[a[x].fa].son[a[a[x].fa].son[1] == f] = x;
}
void splay(int x, int c) {
  int u = x;
  while (u != root) st[++top] = u, u = a[u].fa;
  while (top) push_down(st[top--]);
  int y = a[x].fa;
  for (; y != c;) {
    if (a[y].fa != c) xz((a[a[y].fa].son[0] == y) ^ (a[y].son[0] == x) ? x : y);
    xz(x);
    y = a[x].fa;
  }
  if (c == 0) root = x;
}
int find_front(int x) {
  int u = root, ret, f = 0;
  while (u) {
    push_down(u);
    if (a[u].val < x)
      f = u, ret = u, u = a[u].son[1];
    else
      f = u, u = a[u].son[0];
  }
  splay(f, 0);
  return ret;
}
int find_back(int x) {
  int u = root, ret, f = 0;
  while (u) {
    push_down(u);
    if (a[u].val > x)
      f = u, ret = u, u = a[u].son[0];
    else
      f = u, u = a[u].son[1];
  }
  splay(f, 0);
  return ret;
}
void add(int x) {
  int u = root, f = 0;
  while (u) {
    push_down(u);
    if (a[u].val > x)
      f = u, u = a[u].son[0];
    else
      f = u, u = a[u].son[1];
  }
  a[f].son[x > a[f].val] = ++t;
  a[t].val = x;
  a[t].fa = f;
  splay(t, 0);
}
void del(int x) {
  int f = find_front(x), b = find_back(x);
  splay(f, 0), splay(b, f);
  a[b].son[0] = 0;
}
void updata(int l, int r) {
  int b = find_back(r - 1);
  del(a[b].val);
  if (l != r) {
    int f = find_front(l), b = find_back(r - 1);
    splay(f, 0), splay(b, f);
    int s0 = a[b].son[0];
    if (s0 != 0) a[s0].val++, a[s0].lazy++;
  }
  add(l);
}
void dfs(int u) {
  if (u == 0) return;
  if (a[u].val < INF) ans++;
  dfs(a[u].son[0]);
  dfs(a[u].son[1]);
}
signed main() {
  read(n);
  add(0);
  for (i = 1; i <= n; i++) add(INF + i);
  add(INF * 2);
  for (i = 1; i <= n; i++) {
    int l, r;
    read(l);
    read(r);
    updata(l, r);
  }
  dfs(root);
  printf("%d", ans);
  return 0;
}
