#include <iostream>
#include <vector>

using namespace std;

typedef pair<int,int> P;

void solve(int n) {
    int m;
    cin >> m;
    int p,q,r;
    cin >> p >> q >> r;

    vector<P> card[2];
    card[0].push_back(P(1,n));

    vector<P> temp;
    for(int i=0; i<m; ++i) {
        int x,y;
        cin >> x >> y;

        card[(i+1)%2].clear();

        int j=0;
        int cnt=0;
        int idx,idy;
        while(j<(int)card[i%2].size()) {
            if(cnt+card[i%2][j].second<=x) {
                temp.push_back(card[i%2][j]);
                cnt+=card[i%2][j].second;
                if(cnt==x) idx=(int)temp.size();
                ++j;
            } else if(cnt<x) {
                temp.push_back(P(card[i%2][j].first,x-cnt));
                card[i%2][j].first+=x-cnt;
                card[i%2][j].second-=x-cnt;
                cnt=x;
                idx=(int)temp.size();
            } else if(cnt+card[i%2][j].second<=y) {
                temp.push_back(card[i%2][j]);
                cnt+=card[i%2][j].second;
                if(cnt==y) idy=(int)temp.size();
                ++j;
            } else if(cnt<y) {
                temp.push_back(P(card[i%2][j].first,y-cnt));
                card[i%2][j].first+=y-cnt;
                card[i%2][j].second-=y-cnt;
                cnt=y;
                idy=(int)temp.size();
            } else {
                temp.push_back(card[i%2][j]);
                cnt+=card[i%2][j].second;
                ++j;
            }
        }

        for(int j=idy; j<(int)temp.size(); ++j) {
            card[(i+1)%2].push_back(temp[j]);
        }
        for(int j=idx; j<idy; ++j) {
            card[(i+1)%2].push_back(temp[j]);
        }
        for(int j=0; j<idx; ++j) {
            card[(i+1)%2].push_back(temp[j]);
        }

        temp.clear();
    }

    int ans=0;
    int c=0;

    for(int i=0; i<(int)card[m%2].size(); ++i) {
        int mx,mn;
        if(c>q) break;
        if(c+card[m%2][i].second<p) {
            c+=card[m%2][i].second;
            continue;
        }
        if(c<p) {
            mn=card[m%2][i].first+p-c-1;
        } else {
            mn=card[m%2][i].first;
        }
        if(c+card[m%2][i].second>q) {
            mx=card[m%2][i].first+q-c-1;
        } else {
            mx=card[m%2][i].first+card[m%2][i].second-1;
        }
        ans+=max(0,min(mx,r)-mn+1);
        c+=card[m%2][i].second;
    }

    cout << ans << endl;

    return;
}


int main() {
    int n;
    while(true) {
        cin >> n;
        if(n==0) break;
        solve(n);
    }
    return 0;
}
