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

a , b = 1 , 100000



for i in range(m):

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

    if a <= l:

        a = l

    if b >= r:

        b = r

        

c = b - a + 1

if c > 0:

    print(c)

else:

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

ok = [0] * (n + 2)

ans = 0

for _ in range(m):

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

    ok[l] += 1

    ok[r + 1] -= 1

for i in range(1, n + 2):

    ok[i] += ok[i - 1]

    if ok[i] == m:

        ans += 1

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

n, m = list(map(int, input().split()))
ok = [0] * (n + 2)
ans = 0
for _ in range(m):
    l, r = list(map(int, input().split()))
    ok[l] += 1
    ok[r + 1] -= 1
for i in range(1, n + 2):
    ok[i] += ok[i - 1]
    if ok[i] == m:
        ans += 1
print(ans)

-a, b = 1, 100000 -for i in range(m): +ok = [0] * (n + 2) +ans = 0 +for _ in range(m): -    if a <= l: -        a = l -    if b >= r: -        b = r -c = b - a + 1 -if c > 0: -    print(c) -else: -    print((0)) +    ok[l] += 1 +    ok[r + 1] -= 1 +for i in range(1, n + 2): +    ok[i] += ok[i - 1] +    if ok[i] == m: +        ans += 1 +print(ans)