#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 * 2 + 5;
struct Node {
  int val, tag, sz, rnd, ls, rs;
} t[MAXN];
int newNode(int x) {
  static int m = 0;
  t[++m] = (Node){x, 0, 1, rand(), 0, 0};
  return m;
}
void renew(int rt) {
  int ls = t[rt].ls, rs = t[rt].rs;
  t[rt].sz = t[ls].sz + t[rs].sz + 1;
}
void pushdown(int rt) {
  int ls = t[rt].ls, rs = t[rt].rs, tag = t[rt].tag;
  if (ls) t[ls].tag += tag, t[ls].val += tag;
  if (rs) t[rs].tag += tag, t[rs].val += tag;
  t[rt].tag = 0;
}
int merge(int p, int q) {
  if (!p || !q) return p + q;
  int rt;
  if (t[p].rnd < t[q].rnd)
    pushdown(rt = p), t[rt].rs = merge(t[rt].rs, q);
  else
    pushdown(rt = q), t[rt].ls = merge(p, t[rt].ls);
  renew(rt);
  return rt;
}
void split_by_val(int rt, int &p, int &q, int val) {
  if (!rt) {
    p = q = 0;
    return;
  }
  pushdown(rt);
  if (t[rt].val <= val)
    p = rt, split_by_val(t[rt].rs, t[rt].rs, q, val);
  else
    q = rt, split_by_val(t[rt].ls, p, t[rt].ls, val);
  renew(rt);
}
void split_by_kth(int rt, int &p, int &q, int rk) {
  if (!rt) {
    p = q = 0;
    return;
  }
  pushdown(rt);
  int tmp = t[t[rt].ls].sz + 1;
  if (tmp <= rk)
    p = rt, split_by_kth(t[rt].rs, t[rt].rs, q, rk - tmp);
  else
    q = rt, split_by_kth(t[rt].ls, p, t[rt].ls, rk);
  renew(rt);
}
int getans(int rt) {
  if (!rt) return 2e9;
  pushdown(rt);
  int tmp = getans(t[rt].rs);
  if (tmp != 2e9) return tmp + t[t[rt].ls].sz + 1;
  if (t[rt].val < 2e9) return t[t[rt].ls].sz + 1;
  return getans(t[rt].ls);
}
int main() {
  srand(1234567);
  int n, rt = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) rt = merge(rt, newNode(2e9));
  for (int i = 1, l, r, a, b, c, d; i <= n; i++) {
    scanf("%d%d", &l, &r);
    split_by_val(rt, a, b, l - 1);
    split_by_val(b, b, c, r - 1);
    split_by_kth(c, c, d, 1);
    if (b) t[b].tag++, t[b].val++;
    rt = merge(merge(a, newNode(l)), merge(b, d));
  }
  printf("%d\n", getans(rt));
  return 0;
}
