import Control.Monad (replicateM)
import Data.List (foldl')

type Stack = [(Int,Int)]

main = do
    n <- readLn :: IO Int
    if n == 0 then return () else do
        m <- readLn
        [p,q,r] <- getLine >>= return . map read . words :: IO [Int]
        xys <- replicateM m
                (getLine >>= return . (\[x,y]->(x,y)) . map read . words)
        let shuffled = foldl' (flip $ uncurry shuffle) [(1,n)] xys
        print $ countUnder r $ extract p q $ shuffled
        main

shuffle :: Int -> Int -> Stack -> Stack
shuffle x y stack = stack2 ++ stack1 ++ stack0
    where
    (stack0,stack') = cut x stack
    (stack1,stack2) = cut (y-x) stack'

extract :: Int -> Int -> Stack -> Stack
extract p q stack = stack1
    where
    (_,stack') = cut (p-1) stack
    (stack1,_) = cut (q-p+1) stack'

countUnder :: Int -> Stack -> Int
countUnder r [] = 0
countUnder r ((a,b):ps)
    | b <= r = (b-a+1) + countUnder r ps
    | r < a  = countUnder r ps
    | otherwise = (r-a+1) + countUnder r ps

cut :: Int -> Stack -> (Stack,Stack)
cut 0 stack = ([],stack)
cut k stack = cut' [] stack k
    where
    cut' ps ((a,b):qs) k
        | k <  d = (reverse ((a,a+k-1):ps), (a+k,b):qs)
        | k == d = (reverse ((a,b):ps), qs)
        | k >  d = cut' ((a,b):ps) qs (k-d)
        where
        d = b-a+1