#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 600005, INF = 0x3f3f3f3f;
class Node {
 public:
  int ls, rs, fix, key, sz, tag;
} tr[MAX_N];
void maintain(int x) { tr[x].sz = tr[tr[x].ls].sz + tr[tr[x].rs].sz + 1; }
void add(int x, int val) {
  if (!x) return;
  tr[x].key += val, tr[x].tag += val;
}
void push_down(int x) {
  if (tr[x].tag) {
    add(tr[x].ls, tr[x].tag);
    add(tr[x].rs, tr[x].tag);
    tr[x].tag = 0;
  }
}
pair<int, int> split(int x, int k) {
  pair<int, int> d(0, 0);
  if (!x) return d;
  push_down(x);
  if (tr[tr[x].ls].sz >= k) {
    d = split(tr[x].ls, k);
    tr[x].ls = d.second, d.second = x;
  } else {
    d = split(tr[x].rs, k - tr[tr[x].ls].sz - 1);
    tr[x].rs = d.first, d.first = x;
  }
  maintain(x);
  return d;
}
int merge(int a, int b) {
  push_down(a), push_down(b);
  if (!a || !b) return a + b;
  if (tr[a].fix < tr[b].fix) {
    tr[a].rs = merge(tr[a].rs, b);
    maintain(a);
    return a;
  } else {
    tr[b].ls = merge(a, tr[b].ls);
    maintain(b);
    return b;
  }
}
int N, root;
int find(int x, int val, int k) {
  if (!x) return 0;
  push_down(x);
  if (tr[x].key >= val)
    return find(tr[x].ls, val, k);
  else {
    int res = find(tr[x].rs, val, k + tr[tr[x].ls].sz + 1);
    if (!res)
      return k + tr[tr[x].ls].sz + 1;
    else
      return res;
  }
}
int newNode(int val) {
  static int tot = 0;
  ++tot;
  tr[tot].key = val, tr[tot].fix = rand(), tr[tot].sz = 1;
  return tot;
}
void work(int l, int r) {
  int a = find(root, l, 0), b = find(root, r, 0);
  pair<int, int> x = split(root, a);
  pair<int, int> y = split(x.second, b - a + 1);
  pair<int, int> z = split(y.first, b - a);
  add(z.first, 1);
  root = merge(merge(x.first, newNode(l)), merge(z.first, y.second));
}
int result = 0;
void dfs(int x, int k) {
  if (!x) return;
  push_down(x);
  if (tr[x].key != INF) result = max(result, k + tr[tr[x].ls].sz);
  dfs(tr[x].ls, k), dfs(tr[x].rs, k + tr[tr[x].ls].sz + 1);
}
int main() {
  FILE *fin = stdin, *fout = stdout;
  fscanf(fin, "%d", &N);
  root = newNode(0);
  for (int i = 1; i <= N; ++i) root = merge(root, newNode(INF));
  for (int i = 1; i <= N; ++i) {
    static int l, r;
    fscanf(fin, "%d%d", &l, &r);
    work(l, r);
  }
  dfs(root, 0);
  fprintf(fout, "%d\n", result);
  fclose(fin), fclose(fout);
  return 0;
}
