#include <iostream>
#include <vector>
using namespace std;

typedef pair<int,int> pint;

int main(){
    int n,m,p,q,r;
    while(cin>>n,n){
        cin>>m>>p>>q>>r;
        vector<pint> cards;
        cards.push_back(pint(1,n));
        int x,y;        
        while(m--){
            cin>>x>>y;
            vector<pint> a,b;
            int count=0;
            for(int i=0;i<cards.size();++i){
                count += cards[i].second - cards[i].first +1;
                if(count>=x){
                    a.insert(a.begin(),cards.begin(),cards.begin()+i+1);
                    a[i].second -= count - x;
                    if(count>x){
                        cards[i].first =a[i].second+1;--i;
                    }
                    cards.erase(cards.begin(),cards.begin()+i+1);
                    break;
                }
            }
            count=x;
            for(int i=0;i<cards.size();++i){
                count += cards[i].second - cards[i].first +1;
                if(count>=y){
                    b.insert(b.end(),cards.begin(),cards.begin()+i+1);
                    b[i].second -= count - y;
                    if(count>y){
                        cards[i].first = b[i].second +1;
                        --i;
                    }
                    cards.erase(cards.begin(),cards.begin()+i+1);
                    break;
                }
            }
            cards.insert(cards.end(),b.begin(),b.end());
            cards.insert(cards.end(),a.begin(),a.end());
        }
        int count = 0,ans=0;
        for(int i=0;i<cards.size();++i){
            count += cards[i].second - cards[i].first +1;
            if(count>=p){
                cards[i].first = cards[i].second -count +p;
                cards.erase(cards.begin(),cards.begin()+i);
                break;
            }
        }
        count=p-1;
        for(int i=0;i<cards.size();++i){
            count += cards[i].second - cards[i].first +1;
            if(count>=q){
                cards[i].second += -count+q;              
                cards.erase(cards.begin()+i+1,cards.end());
                break;
            }
        }
        for(int i=0;i<cards.size();++i){
            ans += max(0,min(r-cards[i].first+1,cards[i].second-cards[i].first+1));
        }
        cout<<ans<<endl;
    }
    return 0;
}