#include <bits/stdc++.h>
using namespace std;
using ll = long long;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 3e5 + 7;
struct node {
  node *l, *r;
  int val, add, cnt;
  ll pri;
  void push() {
    for (node *c : {l, r})
      if (c) {
        c->add += add;
      }
    val += add;
    add = 0;
  }
  void pull() {
    cnt = 1;
    for (node *c : {l, r})
      if (c) {
        c->push();
        cnt += c->cnt;
      }
  }
};
using ptr = node *;
inline ptr merge(ptr a, ptr b) {
  if (a)
    a->push();
  else
    return b;
  if (b)
    b->push();
  else
    return a;
  if (a->pri < b->pri) {
    b->l = merge(a, b->l);
    b->pull();
    return b;
  } else {
    a->r = merge(a->r, b);
    a->pull();
    return a;
  }
}
inline pair<ptr, ptr> split(ptr a, int at) {
  if (!a) return {0, 0};
  a->push();
  ptr b;
  if (a->val < at) {
    tie(a->r, b) = split(a->r, at);
    a->pull();
    return {a, b};
  } else {
    tie(b, a->l) = split(a->l, at);
    a->pull();
    return {b, a};
  }
}
inline pair<ptr, ptr> split_sz(ptr a, int at) {
  if (a)
    a->push();
  else
    return {0, 0};
  ptr b;
  int lft = (a->l ? a->l->cnt : 0);
  if (lft < at) {
    tie(a->r, b) = split_sz(a->r, at - lft - 1);
    a->pull();
    return {a, b};
  } else {
    tie(b, a->l) = split_sz(a->l, at);
    a->pull();
    return {b, a};
  }
}
int n, l, r;
ptr t, a, b, c, d, e;
node u[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    tie(a, b) = split(t, l);
    tie(b, c) = split(b, r);
    tie(c, d) = split_sz(c, 1);
    if (b) {
      b->add = 1;
      b->push();
    }
    u[i].val = l;
    u[i].pri = rng();
    u[i].cnt = 1;
    t = merge(merge(a, u + i), merge(b, d));
  }
  cout << t->cnt << endl;
}
