#include <bits/stdc++.h>
using namespace std;
char buf[25];
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
struct tree {
  int f, c[2], siz, v, min, tag;
} t[maxn];
int l[maxn], r[maxn], st[maxn];
int n, rt, num, ans;
int read() {
  int x = 0, f = 0;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = 1;
  } while (ch < '0' || ch > '9');
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return f ? -x : x;
}
void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (!x) {
    putchar('0');
    return;
  }
  int cnt = 0;
  while (x) {
    buf[++cnt] = '0' + x % 10;
    x /= 10;
  }
  for (int i = cnt; i >= 1; --i) putchar(buf[i]);
}
void debug() {
  printf("\n");
  printf("rt:%d\n", rt);
  for (int i = 1; i <= num; ++i) {
    if (t[i].f == 0 && t[i].c[0] == 0 && t[i].c[1] == 0) continue;
    printf("%d:f,c0,c1,siz,v,min,tag:%d %d %d %d %d %d %d\n", i, t[i].f,
           t[i].c[0], t[i].c[1], t[i].siz, t[i].v, t[i].min, t[i].tag);
  }
  printf("\n");
}
bool is(int x) { return t[t[x].f].c[1] == x; }
int create(int x) {
  int y = ++num;
  t[y].siz = 1;
  t[y].v = t[y].min = x;
  t[y].tag = 0;
  return y;
}
void clear(int x) {
  t[x].f = t[x].c[0] = t[x].c[1] = t[x].siz = t[x].v = t[x].min = t[x].tag = 0;
}
void updata(int x) {
  int lc = t[x].c[0], rc = t[x].c[1];
  t[x].siz = t[lc].siz + t[rc].siz + 1;
  t[x].min = t[x].v;
  if (lc) t[x].min = min(t[x].min, t[lc].min);
  if (rc) t[x].min = min(t[x].min, t[rc].min);
}
void down(int x) {
  if (t[x].tag) {
    int lc = t[x].c[0], rc = t[x].c[1], tp = t[x].tag;
    if (lc) t[lc].tag += tp, t[lc].v += tp, t[lc].min += tp;
    if (rc) t[rc].tag += tp, t[rc].v += tp, t[rc].min += tp;
    t[x].tag = 0;
  }
}
void connect(int x, int y, int z) {
  t[x].f = y;
  t[y].c[z] = x;
}
void rotate(int x) {
  int y = t[x].f, z = t[y].f, wx = is(x), wy = is(y);
  connect(t[x].c[wx ^ 1], y, wx);
  connect(y, x, wx ^ 1);
  connect(x, z, wy);
  updata(y);
  updata(x);
}
void splay(int x, int end) {
  if (end == rt) rt = x;
  int y = x, top = 0;
  while (y) {
    st[++top] = y;
    y = t[y].f;
  }
  for (int i = top; i >= 1; --i) down(st[i]);
  int tp = t[end].f;
  while (t[x].f != tp) {
    y = t[x].f;
    if (t[y].f == tp) {
      rotate(x);
      break;
    }
    rotate(is(y) ^ is(x) ? x : y);
    rotate(x);
  }
}
int find(int x) {
  int y = rt;
  while (y) {
    if (t[t[y].c[0]].siz + 1 == x) {
      splay(y, rt);
      return y;
    } else if (t[t[y].c[0]].siz >= x)
      y = t[y].c[0];
    else
      x -= t[t[y].c[0]].siz + 1, y = t[y].c[1];
  }
}
int serch(int x) {
  int y = rt;
  while (y) {
    down(y);
    int lc = t[y].c[0], rc = t[y].c[1];
    if (rc && t[rc].min < x)
      y = rc;
    else if (t[y].v < x) {
      splay(y, rt);
      return y;
    } else
      y = lc;
  }
}
int last(int x) {
  if (t[x].c[0] == 0) return t[x].f;
  int y = t[x].c[0];
  while (t[y].c[1]) y = t[y].c[1];
  splay(y, rt);
  return y;
}
int nxt(int x) {
  if (t[x].c[1] == 0) return t[x].f;
  int y = t[x].c[1];
  while (t[y].c[0]) y = t[y].c[0];
  splay(y, rt);
  return y;
}
void insert(int x, int y) {
  splay(x, rt);
  int w = create(y);
  down(x);
  if (t[x].c[0] == 0) {
    connect(w, x, 0);
  } else {
    int u = t[x].c[0];
    down(u);
    while (t[u].c[1]) u = t[u].c[1], down(u);
    connect(w, u, 1);
    while (u != x) updata(u), u = t[u].f;
  }
  updata(x);
  splay(w, rt);
}
void del(int x) {
  int y = last(x);
  splay(y, rt);
  down(y);
  int z = t[y].c[1];
  down(z);
  if (t[z].c[0] == 0) {
    if (t[z].c[1])
      connect(t[z].c[1], y, 1);
    else
      t[y].c[1] = 0;
  } else {
    while (t[z].c[0]) z = t[z].c[0], down(z);
    z = t[z].f;
    t[z].c[0] = 0;
    while (z != y) updata(z), z = t[z].f;
  }
  clear(x);
  updata(y);
}
void add(int l, int r) {
  int tl = last(l), tr = nxt(r);
  splay(tl, rt);
  splay(tr, t[tl].c[1]);
  int tp = t[tr].c[0];
  t[tp].tag++;
  t[tp].v++;
  t[tp].min++;
  updata(tr);
  updata(tl);
}
int build(int l, int r, int f) {
  if (l > r) return 0;
  int x = create(inf);
  t[x].f = f;
  if (l != r) {
    int mid = (l + r) >> 1;
    t[x].c[0] = build(l, mid - 1, x);
    t[x].c[1] = build(mid + 1, r, x);
    updata(x);
  }
  return x;
}
void get_ans(int x) {
  down(x);
  if (t[x].v != inf) ++ans;
  if (t[x].c[0]) get_ans(t[x].c[0]);
  if (t[x].c[1]) get_ans(t[x].c[1]);
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) l[i] = read(), r[i] = read();
  rt = build(1, n + 1, 0);
  insert(find(1), 0);
  for (int i = 1; i <= n; ++i) {
    int x = serch(l[i]), y = serch(r[i]);
    int tx = nxt(x), ty = nxt(y);
    insert(tx, l[i]);
    del(ty);
    if (x != y) add(tx, y);
  }
  get_ans(rt);
  write(ans - 1);
  putchar('\n');
  return 0;
}
