import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import core.memory;

auto shuffle(SList!(int[]) c, int n, int x, int y) {
	SList!(int[]) d;
	foreach(ci; c) {
		if(ci[0] <= x) {
			if(ci[1] <= x){
				d.insert([ci[0]+n-x, ci[1]+n-x]);
				continue;
			} else {
				d.insert([ci[0]+n-x, n]);
				ci[0] = x+1;
			}
		}
		if(ci[0] <= y) {
			if(ci[1] <= y) {
				d.insert([ci[0]+n-x-y, ci[1]+n-x-y]);
				continue;
			} else {
				d.insert([ci[0]+n-x-y, n-x]);
				ci[0] = y+1;
			}
		}
		d.insert([ci[0]-y, ci[1]-y]);
	}
	return d;
}

void main() {
	int n = to!int(readln().strip());
	while(n) {
		int m = to!int(readln().strip());
		auto pqr = map!(to!int)(readln().strip().split());
		SList!(int[]) c;
		c.insert([pqr[0],pqr[1]]);
		int[][] s;
		foreach(i; 0..m) {
			s ~= array(map!(to!int)(readln().strip().split()));
		}
if(0){
		foreach_reverse(si; s) {
			c = shuffle(c, n, n-si[1], n-si[0]);
		}
		int ans;
		foreach(ci; c) {
			if(ci[0] <= pqr[2]) {
				ans += min(pqr[2],ci[1])-ci[0]+1;
			}
		}
		writeln(ans);
}
		n = to!int(readln().strip());
	}
}