#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int c[N][2], z[N], lazy[N], val[N], T;
int node(int v) {
  T++;
  z[T] = rand() * RAND_MAX + rand();
  val[T] = v;
  return T;
}
void relax(int x) {
  val[x] += lazy[x];
  lazy[(c[x][0])] += lazy[x];
  lazy[(c[x][1])] += lazy[x];
  lazy[x] = 0;
}
void mrg(int &x, int l, int r) {
  if (!l) {
    x = r;
    return;
  }
  if (!r) {
    x = l;
    return;
  }
  if (z[l] > z[r]) {
    relax(l);
    mrg((c[l][1]), (c[l][1]), r);
    x = l;
  } else {
    relax(r);
    mrg((c[r][0]), l, (c[r][0]));
    x = r;
  }
}
void split(int x, int cut, int &l, int &r) {
  if (!x) {
    l = r = 0;
    return;
  }
  relax(x);
  if (val[x] < cut) {
    split((c[x][1]), cut, (c[x][1]), r);
    l = x;
  } else {
    split((c[x][0]), cut, l, (c[x][0]));
    r = x;
  }
}
int first(int x) {
  relax(x);
  if ((c[x][0]))
    return first((c[x][0]));
  else
    return x;
}
const int INF = -1u / 2 - N;
int l[N], r[N];
int get(int x) {
  if (!x) return 0;
  relax(x);
  return get((c[x][0])) + get((c[x][1])) + (val[x] < INF);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> l[i] >> r[i];
  int root = node(0);
  for (int i = 0; i < n; i++) mrg(root, root, node(INF + i));
  for (int i = 0; i < n; i++) {
    int L, M, R;
    split(root, l[i], L, R);
    split(R, r[i], M, R);
    if (M) lazy[M]++;
    int ers;
    split(R, val[first(R)] + 1, ers, R);
    mrg(root, L, node(l[i]));
    mrg(root, root, M);
    mrg(root, root, R);
  }
  cout << get(root) - 1 << endl;
}
