#include <bits/stdc++.h>
using namespace std;
inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline void read(int &x) {
  char c = nc(), b = 1;
  for (; !(c >= '0' && c <= '9'); c = nc())
    if (c == '-') b = -1;
  for (x = 0; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc())
    ;
  x *= b;
}
const int N = 600005;
struct node {
  node *l, *r;
  int val, add, size, fix;
  node() {}
  node(int v) {
    val = v;
    add = 0;
    size = 1;
    l = r = NULL;
    fix = rand() * rand();
  }
} pool[N], *rt;
int ncnt;
typedef pair<node *, node *> abcd;
inline void upd(node *x) {
  x->size = (!x->l ? 0 : x->l->size) + (!x->r ? 0 : x->r->size) + 1;
}
inline void Push(node *x) {
  if (x->add) {
    if (x->l) x->l->add += x->add, x->l->val += x->add;
    if (x->r) x->r->add += x->add, x->r->val += x->add;
    x->add = 0;
  }
}
inline int ran() {
  static int x = 31253125;
  x += (x << 4) + 1;
  return x & 65536;
}
int maxd;
inline node *Merge(node *A, node *B, int d = 0) {
  maxd = max(maxd, d);
  if (!A || !B) return !A ? B : A;
  Push(A);
  Push(B);
  if (A->fix < B->fix) {
    A->r = Merge(A->r, B, d + 1);
    upd(A);
    return A;
  } else {
    B->l = Merge(A, B->l, d + 1);
    upd(B);
    return B;
  }
}
inline abcd Split(node *x, int K, int d = 0) {
  maxd = max(maxd, d);
  if (!x) return abcd(NULL, NULL);
  Push(x);
  if (K <= (!x->l ? 0 : x->l->size)) {
    abcd y = Split(x->l, K, d + 1);
    x->l = y.second;
    upd(x);
    y.second = x;
    return y;
  } else {
    abcd y = Split(x->r, K - (!x->l ? 0 : x->l->size) - 1, d + 1);
    x->r = y.first;
    upd(x);
    y.first = x;
    return y;
  }
}
inline abcd Splitnum(node *x, int num, int d = 0) {
  maxd = max(maxd, d);
  if (!x) return abcd(NULL, NULL);
  Push(x);
  if (x->val > num) {
    abcd y = Splitnum(x->l, num, d + 1);
    x->l = y.second;
    upd(x);
    y.second = x;
    return y;
  } else {
    abcd y = Splitnum(x->r, num, d + 1);
    x->r = y.first;
    upd(x);
    y.first = x;
    return y;
  }
}
int n;
int a[N];
inline void Extract(node *x) {
  if (!x) return;
  Push(x);
  Extract(x->l);
  a[++*a] = x->val;
  Extract(x->r);
}
int main() {
  int l, r;
  read(n);
  pool[++ncnt] = node(0);
  rt = Merge(rt, pool + ncnt);
  for (int i = 1; i <= n; i++)
    pool[++ncnt] = node((1 << 30) + 1), rt = Merge(rt, pool + ncnt);
  for (int i = 1; i <= n; i++) {
    read(l);
    read(r);
    abcd x = Splitnum(rt, l - 1);
    abcd y = Splitnum(x.second, r - 1);
    abcd z = Split(y.second, 1);
    pool[++ncnt] = node(l);
    rt = Merge(x.first, pool + ncnt);
    if (y.first) y.first->val++, y.first->add++;
    rt = Merge(rt, y.first);
    rt = Merge(rt, z.second);
  }
  *a = 0;
  Extract(rt);
  int i;
  for (i = 1; i <= n && a[i + 1] < 1 << 30; i++)
    ;
  i--;
  printf("%d\n", i);
  return 0;
}
