#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
const int INF = 0x3f3f3f3f;
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x;
}
int n, ch[maxn][2], fa[maxn], v[maxn], add[maxn], root = 1, cnt = 2, mn[maxn],
                                                  stk[maxn], top, ans = 2;
inline void update(int rt) {
  mn[rt] = min(v[rt], min(mn[ch[rt][0]], mn[ch[rt][1]]));
}
inline void get_add(int rt, int val) {
  if (!rt) return;
  add[rt] += val;
  mn[rt] += val;
  v[rt] += val;
}
inline void push_down(int rt) {
  if (add[rt]) {
    get_add(ch[rt][0], add[rt]);
    get_add(ch[rt][1], add[rt]);
    update(rt);
    add[rt] = 0;
  }
}
inline void rotate(int a) {
  int b = fa[a], c = fa[b], x = ch[b][1] == a;
  ch[b][x] = ch[a][x ^ 1];
  fa[ch[b][x]] = b;
  ch[a][x ^ 1] = b;
  fa[b] = a;
  fa[a] = c;
  if (c) {
    if (ch[c][0] == b) ch[c][0] = a;
    if (ch[c][1] == b) ch[c][1] = a;
  }
  update(b);
  update(a);
}
inline void splay(int x, int k) {
  if (x == k) return;
  stk[top = 1] = x;
  for (int i = x; fa[i] != k; i = fa[i]) stk[++top] = fa[i];
  for (int i = top; i; --i) push_down(stk[i]);
  for (int y; (y = fa[x]) != k; rotate(x))
    if (fa[y] != k) rotate((ch[fa[y]][0] == y) == (ch[y][0] == x) ? y : x);
  if (!k) root = x;
}
int find_less(int rt, int val) {
  push_down(rt);
  if (v[rt] < val) {
    if (ch[rt][1] && mn[ch[rt][1]] < val)
      return find_less(ch[rt][1], val);
    else
      return rt;
  } else
    return find_less(ch[rt][0], val);
}
void insert(int rt, int val) {
  push_down(rt);
  if (v[rt] < val) {
    if (ch[rt][1])
      insert(ch[rt][1], val);
    else {
      ch[rt][1] = ++cnt;
      fa[cnt] = rt;
      mn[cnt] = v[cnt] = val;
    }
  } else {
    if (ch[rt][0])
      insert(ch[rt][0], val);
    else {
      ch[rt][0] = ++cnt;
      fa[cnt] = rt;
      mn[cnt] = v[cnt] = val;
    }
  }
  update(rt);
}
void pr(int rt) {
  if (ch[rt][0]) pr(ch[rt][0]);
  printf("%d ", v[rt]);
  if (ch[rt][1]) pr(ch[rt][1]);
}
inline void print() {
  printf("\n--------------------------------\n");
  pr(root);
  printf("\n--------------------------------\n");
  for (int i = 1; i <= cnt; ++i)
    printf("%d %d %d %d %d\n", i, ch[i][0], ch[i][1], v[i], add[i]);
  printf("\n--------------------------------\n");
}
int main() {
  n = read();
  ch[1][1] = 2;
  fa[2] = 1;
  v[2] = mn[0] = mn[2] = INF;
  for (int i = 0; i < n; ++i) {
    int l = read(), r = read();
    int L = find_less(root, l), R = find_less(root, r);
    if (L == R) {
      splay(L, 0);
      int k = ch[L][1];
      while (ch[k][0]) push_down(k), k = ch[k][0];
      if (v[k] > l) {
        if (v[k] == INF)
          insert(root, l);
        else
          splay(k, 0), v[k] = l, update(k);
      }
    } else {
      splay(R, 0);
      int k = ch[R][1];
      while (ch[k][0]) push_down(k), k = ch[k][0];
      if (v[k] == INF) {
        insert(root, l);
        splay(cnt, 0);
        splay(k, root);
        get_add(ch[k][0], 1);
        update(k);
        update(root);
      } else {
        splay(k, 0);
        int K = ch[k][0];
        fa[K] = 0;
        while (ch[K][1]) push_down(K), K = ch[K][1];
        splay(K, 0);
        assert(root == K);
        fa[ch[k][1]] = K;
        ch[K][1] = ch[k][1];
        update(K);
        ++ans;
        insert(root, l);
        splay(cnt, 0);
        k = ch[R][1];
        while (ch[k][0]) push_down(k), k = ch[k][0];
        splay(k, root);
        get_add(ch[k][0], 1);
        update(k);
        update(root);
      }
    }
  }
  printf("%d\n", cnt - ans);
  return 0;
}
