#include <bits/stdc++.h>
using namespace std;
namespace Stand_IO_Operation {
inline int read() {
  int f = 1, res = 0, ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') res = res * 10 + ch - 48, ch = getchar();
  return f * res;
}
int _sta[1 << 8];
inline void write(int val) {
  if (!val) {
    putchar('0');
    return;
  }
  if (val < 0) putchar('-'), val = -val;
  *_sta = 0;
  while (val > 0) _sta[++*_sta] = val % 10, val /= 10;
  for (int i = *_sta, _Lim = 1; i >= _Lim; i--) putchar(_sta[i] + 48);
}
};  // namespace Stand_IO_Operation
using namespace Stand_IO_Operation;
const int N = 300005;
int n, Max, block;
inline int Rand() { return rand() << 15 | rand(); }
int root, A[N];
struct Treap {
  int tree_nodes;
  struct node {
    int ls, rs, val, size, add, key;
  } v[N * 2];
  inline int New_node(int val) {
    v[++tree_nodes] = (node){0, 0, val, 1, 0, Rand()};
    return tree_nodes;
  }
  inline void Add(int p, int val) {
    if (p == 0) return;
    v[p].val += val;
    v[p].add += val;
  }
  inline void Pushup(int p) {
    v[p].size = v[v[p].ls].size + v[v[p].rs].size + 1;
  }
  inline void Pushdown(int p) {
    if (!v[p].add) return;
    int ls = v[p].ls, rs = v[p].rs;
    if (ls) Add(ls, v[p].add);
    if (rs) Add(rs, v[p].add);
    v[p].add = 0;
  }
  int Merge(int a, int b) {
    if (!a) return b;
    if (!b) return a;
    Pushdown(a), Pushdown(b);
    if (v[a].key >= v[b].key) {
      v[a].rs = Merge(v[a].rs, b);
      Pushup(a);
      return a;
    } else {
      v[b].ls = Merge(a, v[b].ls);
      Pushup(b);
      return b;
    }
  }
  pair<int, int> Split(int p, int k, int d = 0) {
    Max = max(Max, d);
    if (!p) return make_pair(0, 0);
    Pushdown(p);
    int ls = v[p].ls, rs = v[p].rs;
    if (v[ls].size >= k) {
      pair<int, int> res = Split(ls, k, d + 1);
      v[p].ls = res.second;
      Pushup(res.second = p);
      return res;
    } else {
      pair<int, int> res = Split(rs, k - v[ls].size - 1, d + 1);
      v[p].rs = res.first;
      Pushup(res.first = p);
      return res;
    }
  }
  pair<int, int> Split_val(int p, int val, int d = 0) {
    Max = max(Max, d);
    if (!p) return make_pair(0, 0);
    Pushdown(p);
    int ls = v[p].ls, rs = v[p].rs;
    if (v[p].val > val) {
      pair<int, int> res = Split_val(ls, val, d + 1);
      v[p].ls = res.second;
      Pushup(res.second = p);
      return res;
    } else {
      pair<int, int> res = Split_val(rs, val, d + 1);
      v[p].rs = res.first;
      Pushup(res.first = p);
      return res;
    }
  }
  int Dfs(int u) {
    if (!u) return 0;
    int res = 1;
    Pushdown(u);
    if (v[u].ls) res += Dfs(v[u].ls);
    A[++*A] = v[u].val;
    if (v[u].rs) res += Dfs(v[u].rs);
    return res;
  }
  void Build() { root = New_node(0); }
} T;
void Got(int pos) {
  *A = 0;
  T.Dfs(pos);
  for (int j = 1, _Lim = *A; j <= _Lim; j++) printf("%d ", A[j]);
  puts("");
}
int main() {
  srand(time(0));
  n = read();
  T.Build();
  block = sqrt(n);
  for (int i = 1, _Lim = n; i <= _Lim; i++) {
    int l = read(), r = read();
    pair<int, int> a = T.Split_val(root, l - 1);
    pair<int, int> b = T.Split_val(a.second, r - 1);
    pair<int, int> c = T.Split(b.second, 1);
    int p = T.New_node(l);
    T.Add(b.first, 1);
    root = T.Merge(a.first, p);
    root = T.Merge(root, b.first);
    root = T.Merge(root, c.second);
    if (Max >= 100) {
      printf("The Deep is not right,here Max=%d\n", Max);
      return 0;
    }
  }
  printf("%d\n", T.Dfs(root) - 1);
}
