#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <time.h>
#include <cctype>
#include <deque>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=1e+5+10;
const ut INF=1<<30;
const ld eps=1e-6;
const LL mod=1e+9 + 7;

LL N, M, P, q, r;
deque<pr> cards;

deque<pr> pickCards(int k){
	deque<pr> res;
	while(!cards.empty()){
		pr p = cards.front(); cards.pop_front();
		if(p.S - p.F + 1 == k){
			res.PB(pr(p.F, p.S));
			break;
		}
		else if(p.S - p.F + 1 > k){
			res.PB(pr(p.F, p.F + k - 1));
			cards.push_front(pr(p.F + k, p.S));
			break;
		}
		k -= p.S - p.F + 1;
		res.PB(pr(p.F, p.S));
	}
	return res;
}

int main() {
	while(cin >> N && N){
		cin >> M;
		cin >> P >> q >> r;
		cards.clear();
		cards.PB(pr(1, N));
		REP(i,M){
			int x, y;
			scanf("%d%d",&x, &y);
			deque<pr> top = pickCards(x);
			deque<pr> middle = pickCards(y - x);
			while(!middle.empty()){
				cards.PB(middle.front());
				middle.pop_front();
			}
			while(!top.empty()){
				cards.PB(top.front());
				top.pop_front();
			}
		}
		
		LL now = 0, ans = 0;
		pickCards(P - 1);
		deque<pr> res = pickCards(q - P + 1);
		while(!res.empty()){
			pr c = res.front();
			res.pop_front();
			if(c.S <= r){
				ans += c.S - c.F + 1;
			}
			else if(c.F <= r){
				ans += r - c.F + 1;
			}
		}
		cout << ans << endl;
	}
	return 0;
}