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;
        split(q);
        auto a = split(p);
        foreach (r; a) {
            ret += r.countUnder(l);
        }
        return ret;
    }
    void shuffle(int x, int y) {
        auto a = split(y);
        auto b = split(x);
        auto c = rs;
        rs = a ~ b ~ c;
    }
    R[] split(int x) {
        R[] ret;
        int i = 0;
        int t = 0;
        R b;
        foreach (r; rs) {
            t += r.length;
            if (t >= x) {
                t -= r.length;
                b = r;
                break;
            }
            i++;
        }
        if (t == x) {
            ret = rs[i .. $];
            rs = rs[0 .. i];
        } else {
            ret ~= R(b.from + x - t, b.to);
            ret ~= rs[i + 1 .. $];
            rs = rs[0 .. i];
            rs ~= R(b.from, b.from + x - t);
        }
        return ret;
    }
}

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;
    }
}