#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap, VecDeque};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;
#[allow(dead_code)]
const MOD: i32 = 1000_000_007;
#[allow(dead_code)]
const MODLL: i64 = 1000_000_007;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    loop {
        let n: usize = sc.read();
        if n == 0 {
            break;
        }
        let m: usize = sc.read();
        let (p, q, r): (i32, i32, i32) = (sc.read(), sc.read(), sc.read());
        let mut x: Vec<i32> = vec![0; m];
        let mut y: Vec<i32> = vec![0; m];
        for i in 0..m {
            x[i] = sc.read();
            y[i] = sc.read();
        }
        let x = x; let y = y;

        let mut v: Vec<(i32, i32)> = vec![(1, n as i32)]; // [l, r]

        for i in 0..m {
            let (x, y) = (x[i], y[i]);
            let mut front: Vec<(i32, i32)> = Vec::new();
            let mut mid: Vec<(i32, i32)> = Vec::new();
            let mut back: Vec<(i32, i32)> = Vec::new();
            let mut sum = 0;
            let mut j = 0;
            while j < v.len() { // front
                let (l, r) = v[j];
                if sum + r - l + 1 >= x {
                    front.push((l, l + x - sum - 1));
                    if l + x - sum - 1 == r {
                        sum += r - l + 1;
                        j += 1;
                    }
                    break;
                }
                front.push((l, r));
                j += 1;
                sum += r - l + 1;
            }
            while j < v.len() { // mid
                let (l, r) = v[j];
                let add = max(0, min(x - sum, r - l)); // performed only first
                if sum + r - l + 1 >= y {
                    mid.push((l + add, l + y - sum - 1));
                    if l + y - sum - 1 == r {
                        sum += r - l + 1;
                        j += 1;
                    }
                    break;
                }
                sum += r - l + 1;
                let l = l + add;
                mid.push((l, r));
                j += 1;
            }
            while j < v.len() { // back
                let (l, r) = v[j];
                let add = max(0, min(y - sum, r - l));
                sum += r - l + 1;
                let l = l + add;
                back.push((l, r));
                j += 1;
            }
            v.clear();
            v.append(&mut back);
            v.append(&mut mid);
            v.append(&mut front);
        }

        let mut ans = 0;
        let mut sum = 0;
        for (l, u) in v {
            if sum + u - l + 1 >= p {
                let lv = l + max(p - sum - 1, 0);
                let lr = min(u, l + (q - sum - 1));
                let lr = min(lr, r);
                if lv <= lr {
                    ans += lr - lv + 1;
                }
            }
            sum += u - l + 1;
        }

        println!("{}", ans);
    }
}


Measured memory_bytes: 5056