import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

class M {
    struct R {
        int from, to;
        int length() {
            return to - from;
        }
        int countUnder(int l) {
            if (l < from) return 0;
            if (l >= to) return to - from;
            return l - from + 1;
        }
    }
    R[] rs;
    this(int from, int to) {
        rs = [R(from, to)];
    }
    int count(int p, int q, int l) {
        int ret = 0;
        foreach (r; split(p, q)[1]) {
            ret += r.countUnder(l);
        }
        return ret;
    }
    void shuffle(int x, int y) {
        auto a = split(x, y);
        rs = a[2] ~ a[1] ~ a[0];
    }
    R[][] split(int x, int y) {
        R[][] a = new R[][3];
        int t1 = 0, t2 = 0;
        int index = 0;
        foreach (r; rs) {
            t2 += r.length;
            if (t1 <= x && x < t2) {
                if (t1 != x) a[index] ~= R(r.from, r.from + x - t1);
                index++;
                if (t1 <= y && y < t2) {
                    a[index] ~= R(r.from + x - t1, r.from + y - t1);
                    index++;
                    a[index] ~= R(r.from + y - t1, r.to);
                } else {
                    a[index] ~= R(r.from + x - t1, r.to);
                }
            } else if (t1 <= y && y < t2) {
                if (t1 != y) a[index] ~= R(r.from, r.from + y - t1);
                index++;
                a[index] ~= R(r.from + y - t1, r.to);
            } else {
                a[index] ~= r;
            }
            t1 += r.length;
        }
        return a;
    }
}

void main() {
    int n; 
    while (readf("%d\n", &n), n) {
        int m; readf("%d\n", &m);
        int p, q, r; readf("%d %d %d\n", &p, &q, &r);
        M rs = new M(1, n + 1);
        foreach (i; 0 .. m) {
            int x, y; readf("%d %d\n", &x, &y);
            rs.shuffle(x, y);
        }
        rs.count(p - 1, q, r).writeln;
    }
}