#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int main()
{
	while(true){
		int N,M;
		int PP,QQ,RR;
		int X[5000];
		int Y[5000];
		vector<P>now;
		scanf("%d",&N);
		now.push_back(P(1,N));
		if(N==0)break;
		scanf("%d%d%d%d",&M,&PP,&QQ,&RR);
		for(int i=0;i<M;i++){
			scanf("%d%d",&X[i],&Y[i]);
		}
		for(int i=0;i<M;i++){
			int XX,YY;
			int cou=0;
			for(int j=0;j<now.size();j++){
				int cou1=cou+now[j].second;
				if(cou<=X[i]&&cou1>X[i])XX=j;
				if(cou<=Y[i]&&cou1>Y[i])YY=j;
				cou=cou1;
			}
			vector<P>now11,now12,now13;
			int cou2=0;
			if(XX!=YY){
				for(int j=0;j<XX;j++){
					now11.push_back(now[j]);
					cou2+=now[j].second;
				}
				if(X[i]!=cou2)now11.push_back(P(now[XX].first,X[i]-cou2));
				if(X[i]!=cou2+now[XX].second)now12.push_back(P(now[XX].first+(X[i]-cou2),cou2+now[XX].second-X[i]));
				cou2+=now[XX].second;
				for(int j=XX+1;j<YY;j++){
					now12.push_back(now[j]);
					cou2+=now[j].second;
				}
				if(Y[i]!=cou2)now12.push_back(P(now[YY].first,Y[i]-cou2));
				if(Y[i]!=cou2+now[YY].second)now13.push_back(P(now[YY].first+(Y[i]-cou2),cou2+now[YY].second-Y[i]));
				cou2+=now[YY].second;
				for(int j=YY+1;j<now.size();j++){
					now13.push_back(now[j]);
					cou2+=now[j].second;
				}
			}
			else{
				for(int j=0;j<XX;j++){
					now11.push_back(now[j]);
					cou2+=now[j].second;
				}
				if(X[i]!=cou2)now11.push_back(P(now[XX].first,X[i]-cou2));
				now12.push_back(P(now[XX].first+(X[i]-cou2),Y[i]-X[i]));
				if(Y[i]!=cou2+now[XX].second)now13.push_back(P(now[YY].first+(Y[i]-cou2),cou2+now[YY].second-Y[i]));
				cou2+=now[YY].second;
				for(int j=YY+1;j<now.size();j++){
					now13.push_back(now[j]);
					cou2+=now[j].second;
				}
			}
			now.clear();
			for(int i=0;i<now13.size();i++){
				now.push_back(now13[i]);
			}
			for(int i=0;i<now12.size();i++){
				now.push_back(now12[i]);
			}
			for(int i=0;i<now11.size();i++){
				now.push_back(now11[i]);
			}
		}
		//printf("%d\n",now.size());
		int ans=0;
		int cou11=1;
		for(int i=0;i<now.size();i++){
			if(PP<=cou11&&cou11+now[i].second<=QQ){
				ans+=min(now[i].second,max(0,RR-now[i].first+1));
			}
			else if(cou11+now[i].second<=QQ&&cou11+now[i].second>=PP){
				ans+=min(now[i].second-(PP-cou11),max(0,RR-now[i].first-(PP-cou11)+1));
			}
			else if(PP<=cou11&&QQ>=cou11){
				ans+=min(QQ-cou11+1,max(0,RR-now[i].first+1));
			}
			cou11+=now[i].second;
		}
		printf("%d\n",ans);
	}
}