#include<iostream>
#include<algorithm>
using namespace std;
long n, ng = 0, br = 0;
long a[10000020];//, ps[10000020];
//bool tukOtpaadaLi[10000020];
pair<long, long> interval[50000];
bool bachkaLi(long ind){
    //if(tukOtpaadaLi[ind]){
        return 0;
   // }
   // if(ps[ind]==ng){
        return 1;
   // }
    return 0;
}
int main(){
    cin>>n;
    for(long i=0; i<n; i++){
        cin>>interval[i].first>>interval[i].second;
    }
    sort(interval, interval+n);

    for(long i=0; i<n; i++){
        //cout<<interval[i].first<<" "<<interval[i].second<<"\n";
        //a[interval[i].first] += a[interval[i].first-1];
        a[interval[i].first]++;
        a[interval[i].second+1]--;
        //tukOtpaadaLi[interval[i].second] = true;
    }

    for(int i=1; i<10000000; i++){
       // ps[i] = a[i]+ps[i-1];
        //if(ps[i]>ng){
        //    ng = ps[i];
       // }
    }
    for(int i=1; i<10000000; i++){
        if(bachkaLi(i)){
            br++;
        }
    }
    //for(int i=0; i<20; i++){
    //    cout<<i<<": "<<a[i]<<", "<<ps[i]<<"\n";
   // }
    //cout<<ng<<"\n"<<br;
    return 0;
}
/*
6
7 9
5 6
1 4
7 9
1 8
2 6
*/
