#include <iostream>

using namespace std;

int main()
{   int n;
    cin>>n;
    int a,b;
    cin >>a>>b;
     int minb=b;
     int maxb=b;
    for(int i=2;i<n;i++)
    { cin >>a>>b;
    if(b<minb)
        minb=b;
    if(b>maxb)
        maxb=b;
    }
    int l;
    l=(maxb-minb)-1;
    cout <<l<<endl;
    return 0;
}