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

card=[0 for _ in range(n)]

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

l-=1

for i in range(m-1):

    li, ri = list(map(int, input().split()))

    li-=1

    if li>r or ri<l:

        l=r

        break

    elif li>=l and ri<=r:

        l=li; r=ri

    elif li<=l and ri>=r:

        pass

    elif li<=r and ri>=r:

        l=li

    elif ri>=l and li<=l:

        r=ri

    else:

        pass

print((r-l))

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

card=[0 for _ in range(n)]

l=[]; r=[]

for i in range(m):

    li, ri = list(map(int, input().split()))

    l.append(li)

    r.append(ri)

print((max(0, min(r)-max(l)+1)))

n, m = list(map(int, input().split()))
card = [0 for _ in range(n)]
l, r = list(map(int, input().split()))
l -= 1
for i in range(m - 1):
    li, ri = list(map(int, input().split()))
    li -= 1
    if li > r or ri < l:
        l = r
        break
    elif li >= l and ri <= r:
        l = li
        r = ri
    elif li <= l and ri >= r:
        pass
    elif li <= r and ri >= r:
        l = li
    elif ri >= l and li <= l:
        r = ri
    else:
        pass
print((r - l))

n, m = list(map(int, input().split()))
card = [0 for _ in range(n)]
l = []
r = []
for i in range(m):
    li, ri = list(map(int, input().split()))
    l.append(li)
    r.append(ri)
print((max(0, min(r) - max(l) + 1)))

-l, r = list(map(int, input().split())) -l -= 1 -for i in range(m - 1): +l = [] +r = [] +for i in range(m): -    li -= 1 -    if li > r or ri < l: -        l = r -        break -    elif li >= l and ri <= r: -        l = li -        r = ri -    elif li <= l and ri >= r: -        pass -    elif li <= r and ri >= r: -        l = li -    elif ri >= l and li <= l: -        r = ri -    else: -        pass -print((r - l)) +    l.append(li) +    r.append(ri) +print((max(0, min(r) - max(l) + 1)))