#include <bits/stdc++.h>   using namespace std;   void addmod(int &a, long long b) {     a = (a + b);     if (a >= 1000000007) a -= 1000000007;   }   void mulmod(int &a, long long b) { a = (a * b) % 1000000007; }   template <class T>   bool domin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <class T>   bool domax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   int gi() {     int a;     scanf( %d , &a);     return a;   }   long long gll() {     long long a;     scanf( %lld , &a);     return a;   }   int n;   namespace treap {   struct treap {     int val, size, lazy;     long long rnd;     treap *l, *r;     treap()         : val(0),           size(0),           lazy(0),           rnd((((long long)rand()) << 32) | rand()),           l(NULL),           r(NULL) {}     treap(int val)         : val(val),           size(1),           lazy(0),           rnd((((long long)rand()) << 32) | rand()),           l(NULL),           r(NULL) {}     void push() {       if (lazy == 0) return;       val += lazy;       if (l != NULL) l->lazy += lazy;       if (r != NULL) r->lazy += lazy;       lazy = 0;     }     void updateSz() {       size = 1;       if (l != NULL) size += l->size;       if (r != NULL) size += r->size;     }   };   typedef treap *ptreap;   ptreap root = NULL;   void split(ptreap tp, int key, ptreap &l, ptreap &r) {     if (tp == NULL) {       l = NULL, r = NULL;       return;     }     tp->push();     if (tp->val < key)       l = tp, split(tp->r, key, tp->r, r);     else       r = tp, split(tp->l, key, l, tp->l);     if (l != NULL) l->updateSz();     if (r != NULL) r->updateSz();   }   pair<ptreap, ptreap> split(int v) {     ptreap l, r;     split(root, v, l, r);     return {l, r};   }   pair<ptreap, ptreap> split(ptreap tp, int v) {     ptreap l, r;     split(tp, v, l, r);     return {l, r};   }   void insert(ptreap &tp, ptreap v) {     if (tp == NULL) {       tp = v;       return;     }     tp->push();     if (v->rnd < tp->rnd)       insert(v->val > tp->val ? tp->r : tp->l, v);     else       split(tp, v->val, v->l, v->r), tp = v;     tp->updateSz();   }   void insert(int v) {     ptreap tp = new treap(v);     insert(root, tp);   }   void merge(ptreap &t, ptreap l, ptreap r) {     if (l != NULL) l->push();     if (r != NULL) r->push();     if (l == NULL || r == NULL)       t = (l == NULL ? r : l);     else if (l->rnd > r->rnd)       t = l, merge(t->r, l->r, r);     else       t = r, merge(t->l, l, r->l);     if (t != NULL) t->updateSz();   }   void erase(ptreap &tp, int v) {     if (tp == NULL) return;     tp->push();     if (v == tp->val) {       merge(tp, tp->l, tp->r);     } else {       erase(v < tp->val ? tp->l : tp->r, v);       tp->updateSz();     }   }   int getmin(ptreap tp) {     if (tp == NULL) return 0;     tp->push();     return tp->l == NULL ? tp->val : getmin(tp->l);   }   int getmax(ptreap tp) {     if (tp == NULL) return 0;     tp->push();     return tp->r == NULL ? tp->val : getmax(tp->r);   }   void recalc(ptreap tp) {     if (tp == NULL) return;     tp->push();     recalc(tp->l);     recalc(tp->r);     tp->updateSz();   }   void debug(ptreap &tp) {     if (tp == NULL) return;     tp->push();     if (tp->l != NULL) debug(tp->l);     cout <<        << tp->val <<  :  << tp->rnd <<  :  << tp->size << endl;     if (tp->r != NULL) debug(tp->r);   }   }  // namespace treap   int main() {     n = gi();     for (int i = 0; i < n; i++) {       int l = gi(), r = gi();       auto v = treap::split(l);       auto v2 = treap::split(v.second, r);       if (v2.first != NULL) v2.first->lazy++;       if (v2.second != NULL) {         auto v = treap::getmin(v2.second);         treap::erase(v2.second, v);       }       treap::merge(treap::root, v.first, v2.first);       treap::merge(treap::root, treap::root, v2.second);       treap::insert(l);     }     cout << treap::root->size << endl;     return 0;   }