#include <bits/stdc++.h>
using namespace std;
const long long inf = INT_MAX, df = 3e5 + 7;
long long fa[df], cnt[df], sum[df], ls[df], rs[df], val[df], sta[df], top, n,
    root, tag[df], tot;
inline long long read() {
  long long x = 0, y = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') y = (ch == '-') ? -1 : 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * y;
}
void pushup(long long x) {
  sum[x] = sum[ls[x]] * (ls[x] != 0) + sum[rs[x]] * (rs[x] != 0) + cnt[x];
}
void pushdown(long long x) {
  if (ls[x]) val[ls[x]] += tag[x], tag[ls[x]] += tag[x];
  if (rs[x]) val[rs[x]] += tag[x], tag[rs[x]] += tag[x];
  tag[x] = 0;
  return;
}
void merge(long long x) {
  long long y = fa[x], z = fa[y];
  fa[x] = z, fa[y] = x;
  if (ls[z] == y)
    ls[z] = x;
  else
    rs[z] = x;
  if (ls[y] == x)
    ls[y] = rs[x], rs[x] = y, fa[ls[y]] = y;
  else
    rs[y] = ls[x], ls[x] = y, fa[rs[y]] = y;
  pushup(y), pushup(x);
}
void splay(long long x, long long rt) {
  top = 1;
  sta[top] = x;
  for (long long y = x; y != rt; y = fa[y]) sta[++top] = fa[y];
  for (long long i = (top); i >= (1); --i) pushdown(sta[i]);
  for (long long y = 0; (y = fa[x]) != rt; merge(x))
    if (fa[y] != rt) merge(((ls[y] == x) ^ (ls[fa[y]] == y)) ? x : y);
  if (!rt) root = x;
  return;
}
long long get_back(long long u, long long x) {
  long long lst = 0, ret = 0;
  while (u) {
    if (x < val[u])
      lst = u, pushdown(u), u = ls[ret = u];
    else
      lst = u, pushdown(u), u = rs[u];
  }
  splay(lst, 0);
  return ret;
}
long long get_front(long long u, long long x) {
  long long lst = 0, ret = 0;
  while (u) {
    if (x > val[u])
      lst = u, pushdown(u), u = rs[ret = u];
    else
      lst = u, pushdown(u), u = ls[u];
  }
  splay(lst, 0);
  return ret;
}
void add(long long u, long long x) {
  while (x != val[u]) {
    pushdown(u);
    if (x < val[u]) {
      if (!ls[u]) ls[u] = ++tot, fa[tot] = u, val[tot] = x;
      u = ls[u];
    } else {
      if (!rs[u]) rs[u] = ++tot, fa[tot] = u, val[tot] = x;
      u = rs[u];
    }
  }
  ++cnt[u], ++sum[u];
  splay(u, 0);
}
void det(long long x) {
  long long u = get_front(root, x), v = get_back(root, x);
  splay(u, 0), splay(v, u);
  if (!ls[v]) return;
  --cnt[ls[v]], --sum[ls[v]], --sum[v], --sum[u];
  if (!sum[ls[v]]) {
    fa[ls[v]] = 0;
    ls[v] = 0;
  }
  return;
}
void modity(long long l, long long r) {
  long long x = get_front(root, l), y = get_back(root, r - 1);
  splay(x, 0), splay(y, x);
  if (ls[y]) val[ls[y]]++, tag[ls[y]]++;
  return;
}
int main() {
  n = read();
  add(root, inf), add(root, -inf);
  for (long long i = (1); i <= (n); ++i) {
    long long l = read(), r = read();
    if (i == 1) {
      add(root, l);
      continue;
    }
    long long x = get_back(root, r - 1);
    modity(l, r);
    if (val[x] < inf) det(val[x]);
    add(root, l);
    splay(1, 0);
  }
  return printf("%lld\n", sum[root] - 2), 0;
}
