#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int n, m, p, q, r;

int calc(pii seg, int n) // n=seg.fst????????????????????????
{
    int len = seg.scd - seg.fst + 1; // seg?????????

    if (n < p && p <= n + len - 1) {
        int a = (n + len - 1) - p;

        return calc(pii(seg.scd - a, seg.scd), p);
    }

    if (p <= n && n + len - 1 <= q) {
        return max(min(r - seg.fst + 1, len), 0);
    }

    if (n <= q && q < n + len - 1) {
        int a = q - n;

        return calc(pii(seg.fst, seg.fst + a), n);
    }

    return 0;
}

int main()
{
    omajinai;

    while (cin >> n >> m >> p >> q >> r, n) {
        deque<pii> dat;

        dat.push_back(pii(1, n));

        rep(_, m) {
            int x, y; cin >> x >> y;

            int sum = 0;

            vpii Top, Mid, Bottom;

            // Top?????????
            while (true) {
                pii a = dat.front();

                int v = a.scd - a.fst + 1;

                if (sum + v >= x) {
                    int dif = x - sum-1;

                    sum += dif + 1;

                    Top.push_back(pii(a.fst, a.fst + dif));

                    dat.pop_front();

                    if (a.fst + dif + 1 <= a.scd) dat.push_front(pii(a.fst + dif + 1, a.scd));

                    break;
                } else {
                    Top.PB(a);
                    sum += v;
                }

                dat.pop_front();
            }

            // Mid?????????
            while (true) {
                pii a = dat.front();

                int v = a.scd - a.fst + 1;

                if (sum + v >= y) {
                    int dif = y - sum-1;

                    sum += dif + 1;

                    Mid.push_back(pii(a.fst, a.fst + dif));

                    dat.pop_front();

                    if (a.fst + dif + 1 <= a.scd) dat.push_front(pii(a.fst + dif + 1, a.scd));

                    break;
                } else {
                    Mid.PB(a);
                    sum += v;
                }
                dat.pop_front();
            }

            // Bottom?????????
            while (true) {
                pii a = dat.front();

                int v = a.scd - a.fst + 1;

                if (sum + v == n) {
                    sum += v;

                    Bottom.push_back(pii(a.fst, a.scd));

                    dat.pop_front();

                    break;
                } else {
                    Bottom.PB(a);
                    sum += v;
                }

                dat.pop_front();
            }

            rep(i, Bottom.size()) dat.push_back(Bottom[i]);
            rep(i, Mid.size()) dat.push_back(Mid[i]);
            rep(i, Top.size()) dat.push_back(Top[i]);
        }

        int sum = 1;
        int ans = 0;

        for (pii a : dat) {
            ans += calc(a, sum);
            sum += a.scd - a.fst + 1;
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 3208