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

l = []

r = []

low = 0

high = 10 ** 5 + 1

for i in range(m):

    ll,rr = list(map(int,input().split()))

    l.append(ll)

    r.append(rr)

    low = max(low,ll)

    high = min(high,rr)



if high>=low:

    print((high-low+1))

else:

    print((0))

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



low = 0

high = 10 ** 5 + 1

for i in range(m):

    ll,rr = list(map(int,input().split()))

    

    low = max(low,ll)

    high = min(high,rr)



if high>=low:

    print((high-low+1))

else:

    print((0))

n, m = list(map(int, input().split()))
l = []
r = []
low = 0
high = 10**5 + 1
for i in range(m):
    ll, rr = list(map(int, input().split()))
    l.append(ll)
    r.append(rr)
    low = max(low, ll)
    high = min(high, rr)
if high >= low:
    print((high - low + 1))
else:
    print((0))

n, m = list(map(int, input().split()))
low = 0
high = 10**5 + 1
for i in range(m):
    ll, rr = list(map(int, input().split()))
    low = max(low, ll)
    high = min(high, rr)
if high >= low:
    print((high - low + 1))
else:
    print((0))

-l = [] -r = [] -    l.append(ll) -    r.append(rr)