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

Left = []

Right = []

for i in range(M):

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

    Left.append(l)

    Right.append(r)

if max(Left) > min(Right):

    print((0))

else:

    print((min(Right)-max(Left)+1))
N,M = list(map(int,input().split()))

left = []

right = []

for i in range(M):

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

    left.append(l)

    right.append(r)

if max(left)>min(right):

    print((0))

else:

    print((min(right)-max(left)+1))
N, M = list(map(int, input().split()))
Left = []
Right = []
for i in range(M):
    l, r = list(map(int, input().split()))
    Left.append(l)
    Right.append(r)
if max(Left) > min(Right):
    print((0))
else:
    print((min(Right) - max(Left) + 1))

N, M = list(map(int, input().split()))
left = []
right = []
for i in range(M):
    l, r = list(map(int, input().split()))
    left.append(l)
    right.append(r)
if max(left) > min(right):
    print((0))
else:
    print((min(right) - max(left) + 1))

-Left = [] -Right = [] +left = [] +right = [] -    Left.append(l) -    Right.append(r) -if max(Left) > min(Right): +    left.append(l) +    right.append(r) +if max(left) > min(right): -    print((min(Right) - max(Left) + 1)) +    print((min(right) - max(left) + 1))