#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
int n;
int p,q,r;
int m;
int x[5000];
int y[5000];
int num(int k, int a, int b)
{
	if(k==m){
		int s=min(b-a, max(q-a,0));
		int t=min(b-a, max(p-1-a,0));
		return s-t;
	}
	if(a<x[k]){
		if(b<=x[k]){
			return num(k+1,a+n-x[k],b+n-x[k]);
		}
		else if(b<=y[k]){
			return num(k+1,a+n-x[k],n)+num(k+1,n-y[k],n-y[k]+b-x[k]);
		}
		else
		{
			return num(k+1,a+n-x[k],n)+num(k+1,n-y[k],n-x[k])+num(k+1,0,b-y[k]);
		}
	}
	else if(a<y[k])
	{
		if(b<=y[k]){
			return num(k+1,n-y[k]-x[k]+a,n-y[k]-x[k]+b);
		}
		else
		{
			return num(k+1,n-y[k]-x[k]+a,n-x[k])+num(k+1,0,b-y[k]);
		}
	}
	else
	{
		return num(k+1,a-y[k],b-y[k]);
	}
}
int main() {
while(1)
{
	cin >> n >> m;
	if(n==0)return 0;
	cin >> p >> q >> r;
	for(int i=0;i<m;i++){
		cin >> x[i] >> y[i];
	}
	cout << num(0,0,r) << endl;
}
}