n,m = list(map(int,input().split()))

src = [tuple(map(int,input().split())) for i in range(m)]



l_max,r_min = 0,10**5

for l,r in src:

    l_max = max(l_max,l)

    

for l,r in src:    

    r_min = min(r_min,r)

else:

    if r_min-l_max < 0:

        print((0))

    else:

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

ll = 0

rr = 10**5+1

for i in range(m):

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

    if l > ll:

        ll = l

    if r < rr:

        rr = r

else:

    #print(rr-ll+1)

    if rr-ll+1>n:

        print(n)

    elif rr-ll+1<0:

        print((0))

    else:

        print((rr-ll+1))

n, m = list(map(int, input().split()))
src = [tuple(map(int, input().split())) for i in range(m)]
l_max, r_min = 0, 10**5
for l, r in src:
    l_max = max(l_max, l)
for l, r in src:
    r_min = min(r_min, r)
else:
    if r_min - l_max < 0:
        print((0))
    else:
        print((r_min - l_max + 1))

n, m = list(map(int, input().split()))
ll = 0
rr = 10**5 + 1
for i in range(m):
    l, r = list(map(int, input().split()))
    if l > ll:
        ll = l
    if r < rr:
        rr = r
else:
    # print(rr-ll+1)
    if rr - ll + 1 > n:
        print(n)
    elif rr - ll + 1 < 0:
        print((0))
    else:
        print((rr - ll + 1))

-src = [tuple(map(int, input().split())) for i in range(m)] -l_max, r_min = 0, 10**5 -for l, r in src: -    l_max = max(l_max, l) -for l, r in src: -    r_min = min(r_min, r) +ll = 0 +rr = 10**5 + 1 +for i in range(m): +    l, r = list(map(int, input().split())) +    if l > ll: +        ll = l +    if r < rr: +        rr = r -    if r_min - l_max < 0: +    # print(rr-ll+1) +    if rr - ll + 1 > n: +        print(n) +    elif rr - ll + 1 < 0: -        print((r_min - l_max + 1)) +        print((rr - ll + 1))