#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long a = 0, b = getchar(), c = 1;
  while (!isdigit(b)) c = b == '-' ? -1 : 1, b = getchar();
  while (isdigit(b)) a = a * 10 + b - '0', b = getchar();
  return a * c;
}
const int N = 3e5 + 5;
int n, ab, ac, ans, a[N], b[N], v[N], d[N], c[N];
int cre(int k);
void add(int x, int y);
void jj(int x);
void gao(int x, int k, int &aa, int &bb);
int gg(int x, int y);
int sum(int x, int y);
void down(int x);
int main() {
  n = read();
  while (n--) {
    int l = read(), r = read(), x, y, z;
    gao(ac, r, x, z);
    gao(x, l, x, y);
    add(y, 1);
    if (z) {
      int w = z;
      while (a[w]) {
        jj(w);
        w = a[w];
      }
      gao(z, v[w] + 1, w, z);
    } else
      ans++;
    ac = gg(gg(x, cre(l)), gg(y, z));
  }
  printf("%d", ans);
  return 0;
}
int cre(int k) {
  v[++ab] = k;
  c[ab] = rand();
  return ab;
}
void add(int x, int y) {
  v[x] += y;
  d[x] += y;
}
void jj(int x) {
  add(a[x], d[x]);
  add(b[x], d[x]);
  d[x] = 0;
}
int sum(int x, int y) {
  if (!x or !y) return x | y;
  jj(x), jj(y);
  if (c[x] < c[y])
    return b[x] = gg(b[x], y), x;
  else
    return a[y] = gg(x, a[y]), y;
  return -1;
}
void gao(int x, int k, int &aa, int &bb) {
  if (!x) {
    aa = bb = 0;
    return;
  }
  jj(x);
  if (v[x] < k)
    aa = x, gao(b[x], k, b[aa], bb);
  else
    bb = x, gao(a[x], k, aa, a[bb]);
}
void down(int x) {
  ans++;
  while (x) x = a[x];
  jj(x);
  if (!x) down(a[x]);
}
int gg(int x, int y) {
  if (!x or !y) return x | y;
  jj(x), jj(y);
  if (c[x] < c[y])
    return b[x] = gg(b[x], y), x;
  else
    return a[y] = gg(x, a[y]), y;
  return -1;
}
