#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



int n, m, p, q, r, x, y;

int num(vector<pint> now, int p) {
    int res = 0, tot = 0;
    int i;
    for (i = 0; i < now.size(); ++i) {
        if (tot <= p && p < tot + now[i].second - now[i].first) break;
        tot += now[i].second - now[i].first;
        
        int tmp = min(r, now[i].second) - max(0, now[i].first);
        if (tmp >= 0) res += tmp;
        
        //cout << i << " : " << tmp << endl;
    }
    int tmp = min(r, now[i].first + p - tot) - max(0, now[i].first);
    if (tmp >= 0) res += tmp;
    
    //cout << tmp << endl;
    
    return res;
}

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );
    while (cin >> n) {
        if (n == 0) break;
        cin >> m >> p >> q >> r;
        vector<pint> now(1, pint(0, n));
        
        for (int id = 0; id < m; ++id) {
            cin >> x >> y;
            vector<pint> s1, s2, s3;
            int tot = 0;
            int i;
            for (i = 0; i < now.size(); ++i) {
                if (tot <= x && x < tot + now[i].second - now[i].first) break;
                tot += now[i].second - now[i].first;
                s1.PB(now[i]);
            }
            if (tot < x) s1.PB(pint(now[i].first, now[i].first + x - tot));
            now[i].first = now[i].first + x - tot;
            tot = x;
            
            int j;
            for (j = i; j < now.size(); ++j) {
                if (tot <= y && y < tot + now[j].second - now[j].first) break;
                tot += now[j].second - now[j].first;
                s2.PB(now[j]);
            }
            if (tot < y) s2.PB(pint(now[j].first, now[j].first + y - tot));
            now[j].first = now[j].first + y - tot;
            tot = y;
            
            for (int k = j; k < now.size(); ++k) {
                tot += now[k].second - now[k].first;
                s3.PB(now[k]);
            }

            now.clear();
            for (int i = 0; i < s3.size(); ++i) now.PB(s3[i]);
            for (int i = 0; i < s2.size(); ++i) now.PB(s2[i]);
            for (int i = 0; i < s1.size(); ++i) now.PB(s1[i]);
            
            //cout << endl; COUT(s1); COUT(s2); COUT(s3); COUT(now);
        }
        
        int res1 = num(now, q);
        int res2 = num(now, p-1);
        
        //COUT(res1); COUT(res2);
        
        cout << res1 - res2 << endl;
    }
    return 0;
}


Measured memory_bytes: 1328