#include <bits/stdc++.h>
using namespace std;
int read() {
  bool f = 0;
  int x = 0;
  char c = getchar();
  while (c < '0' || '9' < c) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while ('0' <= c && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return !f ? x : -x;
}
int Root, ncnt;
int siz[1000000 + 5], ch[1000000 + 5][2], key[1000000 + 5], fix[1000000 + 5],
    lazy[1000000 + 5];
void PushUp(int u) {
  siz[u] = siz[ch[u][0]] + siz[ch[u][1]] + 1;
  return;
}
void PushDown(int u) {
  if (!lazy[u]) return;
  key[u] += lazy[u];
  if (ch[u][0]) lazy[ch[u][0]] += lazy[u];
  if (ch[u][1]) lazy[ch[u][1]] += lazy[u];
  lazy[u] = 0;
  return;
}
int Newnode(int id) {
  siz[++ncnt] = 1, key[ncnt] = id, fix[ncnt] = rand();
  return ncnt;
}
int Merge(int u, int v) {
  if (!u || !v) return u + v;
  if (fix[u] < fix[v]) {
    PushDown(u);
    ch[u][1] = Merge(ch[u][1], v);
    PushUp(u);
    return u;
  } else {
    PushDown(v);
    ch[v][0] = Merge(u, ch[v][0]);
    PushUp(v);
    return v;
  }
}
void Split(int u, int id, int &x, int &y) {
  if (!u) {
    x = 0, y = 0;
    return;
  }
  PushDown(u);
  if (key[u] <= id)
    x = u, Split(ch[u][1], id, ch[x][1], y);
  else
    y = u, Split(ch[u][0], id, x, ch[y][0]);
  PushUp(u);
}
int Kth(int u, int k) {
  while (1) {
    if (k <= siz[ch[u][0]])
      u = ch[u][0];
    else if (k == siz[ch[u][0]] + 1)
      break;
    else
      k -= siz[ch[u][0]] + 1, u = ch[u][1];
  }
  return u;
}
int GetAns(int u) {
  if (!u) return 0;
  PushDown(u);
  return GetAns(ch[u][0]) + GetAns(ch[u][1]) + (key[u] < 0x3f3f3f3f);
}
int l[1000000 + 5], r[1000000 + 5];
int main() {
  srand(time(NULL));
  int n = read();
  for (int i = 1; i <= n; i++) l[i] = read(), r[i] = read();
  for (int i = 1; i <= n; i++) Merge(Root, i + 0x3f3f3f3f);
  int L, M, R, tmp;
  for (int i = 1; i <= n; i++) {
    Split(Root, l[i] - 1, L, R);
    Split(R, r[i] - 1, M, R);
    if (M) lazy[M]++;
    Split(R, key[Kth(R, 1)], tmp, R);
    Root = Merge(Merge(L, Newnode(l[i])), Merge(M, R));
  }
  printf("%d\n", GetAns(Root));
  return 0;
}
