import std.stdio;
import std.algorithm;
import core.stdc.stdio;

static immutable maxM = 5000;

struct t{
	int idx;
	int len;
}

class State{
	int[] sizes;
	t[][] data;
	this(){
		sizes = new int[3];
		data = new t[][3];
		t[] buf = new t[3*(maxM*2+1)];
		for(int i=0;i<3;i++){
			data[i] = buf[i*(maxM*2+1)..(i+1)*(maxM*2+1)];
		}
	}
	void Clear(){
		sizes[] = 0;
	}
}

void main(){
	State now = new State;
	State next = new State;
	
	while(true){
	
	int n,m,p,q,r;
	scanf("%d",&n);
	if(n==0)
		break;
	scanf("%d%d%d%d",&m,&p,&q,&r);
	p--;
	now.Clear;
	now.data[0][now.sizes[0]++] = t(1,n);
	for(int _=0;_<m;_++){
		next.Clear;
		int x,y;
		scanf("%d%d",&x,&y);
		int len=0;
		for(int i=0;i<3;i++){
			for(int j=0;j<now.sizes[i];j++){
				t a = now.data[i][j];
				t b;
				if(len < x){
					if(len+a.len > x){
						b.len = len+a.len-x;
						a.len -= b.len;
						b.idx = a.idx+a.len;
						now.data[i][j] = b;
						j--;
					}
					next.data[2][next.sizes[2]++] = a;
				}else if(len < y){
					if(len+a.len > y){
						b.len = len+a.len-y;
						a.len -= b.len;
						b.idx = a.idx+a.len;
						now.data[i][j] = b;
						j--;
					}
					next.data[1][next.sizes[1]++] = a;
				}else{
					next.data[0][next.sizes[0]++] = a;
				}
				len += a.len;
			}
		}
		swap(now,next);
	}
	int res=0;
	int len=0;
	for(int i=0;i<3;i++){
		for(int j=0;j<now.sizes[i];j++){
			t a = now.data[i][j];
			t b;
			if(len < p){
				if(len+a.len > p){
					b.len = len+a.len-p;
					a.len -= b.len;
					b.idx = a.idx+a.len;
					now.data[i][j] = b;
					j--;
				}
			}else if(len < q){
				if(len+a.len > q){
					a.len = q-len;
				}
				res += max(0,min(a.len,r+1-a.idx));
			}
			len += a.len;
		}
	}
	printf("%d\n",res);
	
	}
}