#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
//typedef pair<int,int>P;
#define INF 1000000009

typedef struct D{int s,e;}D;//(s,e]

int N,M,P,Q,R,x,y,res;

void Qmov(queue<D> &s,queue<D> &d,int len)
{
	for(int c=0;c<len&&!s.empty();)
	{
		D now=s.front();s.pop();
		if(c+(now.e-now.s)>len)
		{
			D rev={now.s+(len-c),now.e};
			now.e=now.s+(len-c);
			queue<D>tmp;
			tmp.push(rev);
			Qmov(s,tmp,INF);
			Qmov(tmp,s,INF);
		}
		c+=(now.e-now.s);
		d.push(now);
	}
}


int main()
{
	for(;scanf("%d",&N),N;)
	{
		queue<D>q,A,B,C;
		D tmp={1,N+1};
		q.push(tmp);
		scanf("%d%d%d%d",&M,&P,&Q,&R);
		for(int i=0;i<M;i++)
		{
			scanf("%d%d",&x,&y);
			Qmov(q,A,x);
			Qmov(q,B,y-x);
			Qmov(q,C,INF);
			Qmov(C,q,INF);
			Qmov(B,q,INF);
			Qmov(A,q,INF);
		}
		P--;Q--;res=0;
		for(int i=0;i<=Q;)
		{
			D tmp=q.front();q.pop();
			int len=tmp.e-tmp.s;
			if(i+len<P||i>Q)
			{
			}
			else
			{
				int s=i>P?tmp.s:tmp.s+(P-i);
				int e=i+len<Q?tmp.e-1:tmp.s+(Q-i);
				if(s<=R)
					res+=min(R,e)-s+1;
			}
			i+=len;
			
		}
		printf("%d\n",res);
	}
}