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

l = 0

r = n

for i in range(m):

    lt, rt = list(map(int, input().split()))

    l = max(l, lt)

    r = min(r, rt)

if(l<=r):

    print((r - l + 1))

else:

    print((0))

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

l = 0

r = n

for i in range(m):

    lt, rt = list(map(int, input().split()))

    if (lt > l):

        l = lt

    if (rt < r):

        r = rt

if (r <l):

    print((0))

else:

    print((r-l+1))

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

n, m = list(map(int, input().split()))
l = 0
r = n
for i in range(m):
    lt, rt = list(map(int, input().split()))
    if lt > l:
        l = lt
    if rt < r:
        r = rt
if r < l:
    print((0))
else:
    print((r - l + 1))

-    l = max(l, lt) -    r = min(r, rt) -if l <= r: +    if lt > l: +        l = lt +    if rt < r: +        r = rt +if r < l: +    print((0)) +else: -else: -    print((0))