#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int main()
{
    while (1)
    {
        int n, m, p, q, r, x, y, sum, cnt;
        bool ok;
        vector<pair<int, int>> vec, v1, v2, v3;
        cin>>n;
        if (!n) break;
        cin>>m>>p>>q>>r;
        vec.push_back({1,n});
        for (int i=0; i<m; i++)
        {
            sum=0;
            ok=true;
            v1.clear();
            v2.clear();
            v3.clear();
            cin>>x>>y;
            auto u=vec.begin();
            cnt=0;
            while (ok)
            {
                u++;
                if (cnt==0) { u--; cnt=1; }
                sum+=u->second;
                if (sum<=x) v1.push_back({u->first, u->second});
                else
                {
                    sum-=u->second;
                    if (x!=sum)
                    {
                        v1.push_back({u->first, (x-sum)});
                        u->first+=(x-sum);
                        u->second-=(x-sum);
                        sum+=(x-sum);
                    }
                    ok=false;
                }
            }
            ok=true;
            cnt=0;
            while (ok)
            {
                u++;
                if (cnt==0) { u--; cnt=1; }
                sum+=u->second;
                if (sum<=y) v2.push_back({u->first, u->second});
                else
                {
                    sum-=u->second;
                    if (y!=sum)
                    {
                        v2.push_back({u->first, (y-sum)});
                        u->first+=(y-sum);
                        u->second-=(y-sum);
                        sum+=(y-sum);
                    }
                    ok=false;
                }
            }
            cnt=0;
            while (u!=vec.end())
            {
                u++;
                if (cnt==0) { u--; cnt=1; }
                if (u!=vec.end())
                {
                    v3.push_back({u->first, u->second});
                }
            }
            vec.swap(v3);
            vec.insert(vec.end(), v2.begin(), v2.end());
            vec.insert(vec.end(), v1.begin(), v1.end());
        }
        cnt=0;
        sum=0;
        ok=true;
        auto u=vec.begin();
        v1.clear();
        while (ok)
        {
            u++;
            if (cnt==0) { u--; cnt=1; }
            sum+=u->second;
            if (sum>=p)
            {
                sum-=u->second;
                u->first+=(p-sum-1);
                u->second-=(p-sum-1);
                sum+=(p-sum-1);
                ok=false;
            }
        }
        cnt=0;
        ok=true;
        while (ok)
        {
            u++;
            if (cnt==0) { u--; cnt=1; }
            sum+=u->second;
            if (sum<=q) v1.push_back({u->first, u->second});
            else
            {
                sum-=u->second;
                if (q!=sum) v1.push_back({u->first, (q-sum)});
                ok=false;
            }
        }
        cnt=0;
        for (auto w : v1)
        {
            if (w.first<=r) cnt+=min(r-w.first+1, w.second);
        }
        cout<<cnt<<'\n';
    }
    return 0;
}



Measured memory_bytes: 3268