#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse3", "sse2", "sse")
#pragma GCC target("avx", "sse4", "sse4.1", "sse4.2", "ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline", "fast-math", "unroll-loops", \
                     "no-stack-protector")
using namespace std;
inline char readchar() {
  const int S = 1 << 20;
  static char buf[S], *p = buf, *q = buf;
  if (p == q && (q = (p = buf) + fread(buf, 1, S, stdin)) == buf) return EOF;
  return *p++;
}
inline void input(int& _x) {
  _x = 0;
  int _tmp = 1;
  char _tc = readchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = readchar();
  if (_tc == '-') _tc = readchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x = _x * 10 + (_tc - 48), _tc = readchar();
  _x *= _tmp;
}
inline void output(int _x) {
  char _buff[20];
  int _f = 0;
  if (_x == 0) putchar('0');
  while (_x > 0) {
    _buff[_f++] = _x % 10 + '0';
    _x /= 10;
  }
  for (_f -= 1; _f >= 0; _f--) putchar(_buff[_f]);
  putchar('\n');
}
inline int ran() {
  static int x = 71222217;
  return (x = 0xdefaced * x + 1) & INT_MAX;
}
const bool LEFT = 0, RIGHT = 1;
struct node {
  node *L = 0, *R = 0, *P = 0;
  int l, r, val, ltadd = 0, size = 1, key;
  node(int a, int b, int c) { l = a, r = b, val = c, key = ran(); }
  node(node* a) { l = a->l, r = a->r, val = a->val, key = ran(); }
  inline void upd(int i) { l += i, r += i, val += i, ltadd += i; }
  inline friend int sz(node* x) { return x ? x->size : 0; }
  inline void down() {
    if (L) L->upd(ltadd);
    if (R) R->upd(ltadd);
    ltadd = 0;
  }
  inline void up() { size = 1 + sz(L) + sz(R); }
  void check() {
    if (L) L->check();
    if (R) R->check();
    assert(size == 1 + sz(L) + sz(R));
  }
  pair<node*, node*> split(int i, bool targ) {
    down();
    if (l <= i && i <= r) {
      auto LL = L, RR = R;
      L = R = 0;
      up();
      node *ln, *rn;
      if (targ == LEFT) {
        rn = r == i ? nullptr : new node(i + 1, r, val);
        r = i;
        ln = this;
      } else {
        ln = l == i ? nullptr : new node(l, i - 1, val);
        l = i;
        rn = this;
      }
      return {_merge(LL, ln), _merge(rn, RR)};
    }
    if (i < l) {
      if (!L) return {0, this};
      auto x = L->split(i, targ);
      L = x.second;
      up();
      return {x.first, this};
    }
    if (i > r) {
      if (!R) return {this, 0};
      auto x = R->split(i, targ);
      R = x.first;
      up();
      return {this, x.second};
    }
  }
  node* last() { return R ? down(), R->last() : this; }
  node* first() { return L ? down(), L->first() : this; }
  friend node* _merge(node* L, node* R) {
    if (!L) return R;
    if (!R) return L;
    if (L->key < R->key) {
      L->down();
      L->R = _merge(L->R, R);
      L->up();
      return L;
    } else {
      R->down();
      R->L = _merge(L, R->L);
      R->up();
      return R;
    }
  }
  friend node* merge(node* L, node* R, int i = 1) {
    if (!i) return _merge(L, R);
    if (!L) return R;
    if (!R) return L;
    node *c1 = L->last(), *c2 = R->first();
    if (c1->val >= c2->val) {
      c1->r = c2->r;
      auto [x, r] = R->split(c2->r, LEFT);
      delete x;
      return merge(L, r, i - 1);
    }
    return _merge(L, R);
  }
  ostream& print(ostream& out = cout) {
    down();
    if (L) L->print(out);
    if (R) R->print(out);
    return out;
  }
}* root = new node(0, 1000000000, 0);
ostream& operator<<(ostream& out, node* n) {
  if (n) return n->print(out);
  return out << "null";
}
signed main() {
  int n;
  input(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    input(a);
    input(b);
    auto [l, _x] = root->split(a, RIGHT);
    auto [m, r] = _x->split(b, LEFT);
    auto [m2, x] = m->split(b, RIGHT);
    delete x;
    m = merge(new node(a - 1, a - 1, l->last()->val), m2);
    m->upd(1);
    root = merge(l, merge(m, r, 2), 0);
  }
  root->check();
  output(root->last()->val);
}
