# Original solution
def shuffle(deck,x,y):
    cnter = 0
    i = 0
    sectiona = []
    while (cnter < x):
        nextsize = deck[i][1] - deck[i][0] + 1
        if(x-cnter >= nextsize):
            sectiona.append(deck[i])
            cnter += nextsize
            i += 1
        else:
            sectiona.append([deck[i][0],deck[i][0] + x-cnter - 1])
            deck[i][0] = deck[i][0] + x-cnter
            cnter = x

    sectionb = []
    while (cnter < y):
        nextsize = deck[i][1] - deck[i][0] + 1
        if(y-cnter >= nextsize):
            sectionb.append(deck[i])
            cnter += nextsize
            i += 1
        else:
            sectionb.append([deck[i][0],deck[i][0] + y-cnter - 1])
            deck[i][0] = deck[i][0] + y-cnter
            cnter = y

    newdeck = deck[i:] + sectionb + sectiona
    return newdeck

def hitnum(a,r):
    if a[1] <= r:
        return a[1]-a[0]+1
    elif a[0] <= r:
        return r-a[0]+1
    else:
        return 0

while True:
    n = int(eval(input()))
    if n==0: break
    deck = [[1,n]]
    m = int(eval(input()))

    p,q,r = list(map(int,input().split()))

    for i in range(m):
        x,y = list(map(int,input().split()))
        deck = shuffle(deck, x, y)
    deck = shuffle(deck,0,p-1)

    answer = 0
    cnter = 0
    i = 0
    while (cnter < q-p+1):
        nextsize = deck[i][1] - deck[i][0] + 1
        if(q-p+1-cnter >= nextsize):
            answer += hitnum(deck[i],r)
            cnter += nextsize
            i += 1
        else:
            answer += hitnum([deck[i][0],deck[i][0] + q-p+1-cnter - 1],r)
            deck[i][0] = deck[i][0] + q-p+1-cnter
            cnter = q-p+1

    print(answer)

# Optimized solution
def shuffle(deck,x,y):
    cnter = 0
    i = 0
    sectiona = sectionb = []
    while (cnter < x):
        nextsize = deck[i][1] - deck[i][0] + 1
        if(x-cnter >= nextsize):
            cnter += nextsize
            i += 1
        else:
            sectiona = [[deck[i][0],deck[i][0] + x-cnter - 1]]
            deck[i][0] = deck[i][0] + x-cnter
            cnter = x
    memoa = i
    while (cnter < y):
        nextsize = deck[i][1] - deck[i][0] + 1
        if(y-cnter >= nextsize):
            cnter += nextsize
            i += 1
        else:
            sectionb = [[deck[i][0],deck[i][0] + y-cnter - 1]]
            deck[i][0] = deck[i][0] + y-cnter
            cnter = y

    newdeck = deck[i:] + deck[memoa:i] + sectionb + deck[0:memoa] + sectiona
    return newdeck

def hitnum(a,r):
    if a[1] <= r:
        return a[1]-a[0]+1
    elif a[0] <= r:
        return r-a[0]+1
    else:
        return 0

while True:
    n = int(eval(input()))
    if n==0: break
    deck = [[1,n]]
    m = int(eval(input()))

    p,q,r = list(map(int,input().split()))

    for i in range(m):
        x,y = list(map(int,input().split()))
        deck = shuffle(deck, x, y)

    deck = shuffle(deck,0,p-1)

    answer = 0
    cnter = 0
    i = 0
    while (cnter < q-p+1):
        nextsize = deck[i][1] - deck[i][0] + 1
        if(q-p+1-cnter >= nextsize):
            answer += hitnum(deck[i],r)
            cnter += nextsize
            i += 1
        else:
            answer += hitnum([deck[i][0],deck[i][0] + q-p+1-cnter - 1],r)
            deck[i][0] = deck[i][0] + q-p+1-cnter
            cnter = q-p+1

    print(answer)