#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
const int INF = 0x3f3f3f3f;
template <typename T>
inline void read(T &AKNOI) {
  T x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  AKNOI = flag * x;
}
template <typename T>
inline void cmin(T &x, T y) {
  if (x > y) x = y;
}
template <typename T>
inline void cmax(T &x, T y) {
  if (x < y) x = y;
}
int n, ans;
int root, fa[MAXN], ch[MAXN][2], key[MAXN], tag[MAXN], stk[MAXN], top, tot;
inline void puttag(int x, int tg) {
  key[x] += tg;
  tag[x] += tg;
}
inline void pushdown(int x) {
  if (tag[x]) {
    if (ch[x][0]) puttag(ch[x][0], tag[x]);
    if (ch[x][1]) puttag(ch[x][1], tag[x]);
    tag[x] = 0;
  }
}
void Rotate(int x, int t) {
  int y = fa[x], z = fa[y], c = ch[x][1 - t];
  if (z)
    ch[z][ch[z][1] == y] = x;
  else
    root = x;
  ch[x][1 - t] = y;
  ch[y][t] = c;
  fa[x] = z;
  fa[y] = x;
  fa[c] = y;
}
void Splay(int x, int to) {
  stk[top = 1] = x;
  for (int i = x; fa[i]; i = fa[i]) {
    stk[++top] = fa[i];
  }
  while (top) pushdown(stk[top--]);
  for (int y = fa[x], z = fa[y]; y != to; y = fa[x], z = fa[y]) {
    int f1 = (ch[y][1] == x), f2 = (ch[z][1] == y);
    if (z == to) {
      Rotate(x, f1);
    } else if (f1 ^ f2) {
      Rotate(x, f1);
      Rotate(x, f2);
    } else {
      Rotate(y, f2);
      Rotate(x, f1);
    }
  }
}
void Insert(int &x, int ff, int k) {
  if (!x) {
    x = ++tot;
    fa[x] = ff;
    ch[x][0] = ch[x][1] = 0;
    key[x] = k;
    Splay(x, 0);
    return;
  }
  pushdown(x);
  Insert(ch[x][key[x] <= k], x, k);
}
int GetPre(int x) {
  Splay(x, 0);
  x = ch[x][0];
  while (ch[x][1]) x = ch[x][1];
  return x;
}
int GetSuc(int x) {
  Splay(x, 0);
  x = ch[x][1];
  while (ch[x][0]) x = ch[x][0];
  return x;
}
void Delete(int x) {
  int pre = GetPre(x), suc = GetSuc(x);
  Splay(pre, 0);
  Splay(suc, pre);
  ch[suc][0] = 0;
}
int Search(int k) {
  int x = root, ret;
  while (x) {
    pushdown(x);
    if (key[x] < k) {
      ret = x;
      x = ch[x][1];
    } else {
      x = ch[x][0];
    }
  }
  return ret;
}
void DP(int l, int r) {
  int pre = Search(l), ed = Search(r), suc = GetSuc(ed);
  if (pre != ed) {
    Splay(pre, 0);
    Splay(suc, pre);
    puttag(ch[suc][0], 1);
  }
  if (suc != 1) {
    Delete(suc);
    --ans;
  }
  Insert(root, 0, l);
  ++ans;
}
void solve() {
  Insert(root, 0, INF);
  Insert(root, 0, -INF);
  read(n);
  for (int i = 1; i <= n; ++i) {
    int l, r;
    read(l);
    read(r);
    DP(l, r);
  }
  printf("%d\n", ans);
}
int main() {
  solve();
  return 0;
}
