#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const int N = 300010;
inline int read() {
  int s = 0, w = 1;
  register char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * w;
}
int n, root, ch[N][2], siz[N], rnd[N], val[N], tag[N], cnt;
inline void Push_Up(int x) { siz[x] = siz[ch[x][0]] + siz[ch[x][1]] + 1; }
inline int New_Node(int x) {
  val[++cnt] = x, siz[cnt] = 1, rnd[cnt] = rand();
  return cnt;
}
inline void Push_Down(int x) {
  if (!tag[x]) return;
  if (ch[x][0]) tag[ch[x][0]] += tag[x], val[ch[x][0]] += tag[x];
  if (ch[x][1]) tag[ch[x][1]] += tag[x], val[ch[x][1]] += tag[x];
  tag[x] = 0;
}
void Split(int root, int k, int &x, int &y) {
  if (!root) {
    x = y = 0;
    return;
  }
  Push_Down(root);
  if (val[root] <= k)
    x = root, Split(ch[root][1], k, ch[root][1], y);
  else
    y = root, Split(ch[root][0], k, x, ch[root][0]);
  Push_Up(root);
}
int Merge(int x, int y) {
  if (!x || !y) return x | y;
  Push_Down(x), Push_Down(y);
  if (rnd[x] < rnd[y]) {
    ch[x][1] = Merge(ch[x][1], y), Push_Up(x);
    return x;
  } else {
    ch[y][0] = Merge(x, ch[y][0]), Push_Up(y);
    return y;
  }
}
inline void Insert(int k) {
  int x, y;
  Split(root, k, x, y);
  root = Merge(Merge(x, New_Node(k)), y);
}
inline void Delete(int k) {
  int x, y, z;
  Split(root, k, x, y);
  Split(x, k - 1, x, z);
  z = Merge(ch[z][0], ch[z][1]);
  root = Merge(Merge(x, z), y);
}
inline int Kth(int x, int k) {
  if (!x || !k) return 0;
  while (1) {
    if (siz[ch[x][0]] >= k)
      x = ch[x][0];
    else if (siz[ch[x][0]] == k - 1)
      return x;
    else
      k -= siz[ch[x][0]] + 1, x = ch[x][1];
  }
}
inline int GetNxt(int k) {
  int x, y;
  Split(root, k, x, y);
  int bk = val[Kth(y, 1)];
  root = Merge(x, y);
  return bk;
}
inline void UpDate(int l, int r) {
  int x, y, z;
  Split(root, l - 1, x, y);
  Split(y, r, y, z);
  if (y) val[y]++, tag[y]++;
  root = Merge(x, Merge(y, z));
}
signed main() {
  srand(time(NULL));
  n = read();
  for (register int i = 1; i <= n; i++) {
    int l, r;
    l = read(), r = read();
    int g = GetNxt(r - 1);
    UpDate(l, r - 1);
    Insert(l);
    if (g) Delete(g);
  }
  printf("%d\n", siz[root]);
  return 0;
}
