N, M = list(map(int, input().split()))

L1, R1 = list(map(int, input().split()))

flag = 0

def find_key(L1,R1,L2,R2):

    if R1 < L2 or R2 < L1:

        return(False)

    else:

        a = [R1,L1,R2,L2]

        a.sort()

        return(a[1],a[2])



for i in range(M - 1):

    L,R = list(map(int, input().split()))

    if find_key(L1,R1,L,R) != False:

        L1,R1 = find_key(L1,R1,L,R)

    else:

        flag = 1

        print((0))

        break

if flag == 0:

    print((R1-L1+1))
n,m=list(map(int,input().split()))

ml=0

mr=100000

for i in range(m):

  l,r=list(map(int,input().split()))

  ml=max(ml,l)

  mr=min(mr,r)

  if ml>mr:

    break

if ml<=mr:

  print((mr-ml+1))

else:

  print((0))
N, M = list(map(int, input().split()))
L1, R1 = list(map(int, input().split()))
flag = 0


def find_key(L1, R1, L2, R2):
    if R1 < L2 or R2 < L1:
        return False
    else:
        a = [R1, L1, R2, L2]
        a.sort()
        return (a[1], a[2])


for i in range(M - 1):
    L, R = list(map(int, input().split()))
    if find_key(L1, R1, L, R) != False:
        L1, R1 = find_key(L1, R1, L, R)
    else:
        flag = 1
        print((0))
        break
if flag == 0:
    print((R1 - L1 + 1))

n, m = list(map(int, input().split()))
ml = 0
mr = 100000
for i in range(m):
    l, r = list(map(int, input().split()))
    ml = max(ml, l)
    mr = min(mr, r)
    if ml > mr:
        break
if ml <= mr:
    print((mr - ml + 1))
else:
    print((0))

-N, M = list(map(int, input().split())) -L1, R1 = list(map(int, input().split())) -flag = 0 - - -def find_key(L1, R1, L2, R2): -    if R1 < L2 or R2 < L1: -        return False -    else: -        a = [R1, L1, R2, L2] -        a.sort() -        return (a[1], a[2]) - - -for i in range(M - 1): -    L, R = list(map(int, input().split())) -    if find_key(L1, R1, L, R) != False: -        L1, R1 = find_key(L1, R1, L, R) -    else: -        flag = 1 -        print((0)) +n, m = list(map(int, input().split())) +ml = 0 +mr = 100000 +for i in range(m): +    l, r = list(map(int, input().split())) +    ml = max(ml, l) +    mr = min(mr, r) +    if ml > mr: -if flag == 0: -    print((R1 - L1 + 1)) +if ml <= mr: +    print((mr - ml + 1)) +else: +    print((0))