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

a = []

for i in range(m):

    a.append(input().split())

haba = a[0]

for i in a:

    if int(haba[0]) <= int(i[0]) <= int(haba[1]):

        haba[0] = i[0]

    elif int(haba[1]) < int(i[0]):

        print((0))

        exit()

    if int(haba[0]) <= int(i[1]) <= int(haba[1]):

        haba[1] = i[1]

    elif int(i[1]) < int(haba[0]):

        print((0))

        exit()

if n < int(haba[0]):

    ans = 0

elif int(haba[0]) <= n <= int(haba[1]):

    ans = n - int(haba[0]) + 1

else:

    ans = int(haba[1]) - int(haba[0]) + 1

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

a = []

for i in range(m):

    a.append(list(map(int, input().split())))

haba = a[0]

for i in a:

    if haba[0] <= i[0] <= haba[1]:

        haba[0] = i[0]

    elif haba[1] < i[0]:

        print((0))

        exit()

    if haba[0] <= i[1] <= haba[1]:

        haba[1] = i[1]

    elif i[1] < haba[0]:

        print((0))

        exit()

if n < haba[0]:

    ans = 0

elif haba[0] <= n <= haba[1]:

    ans = n - haba[0] + 1

else:

    ans = haba[1] - haba[0] + 1

print(ans)
n, m = list(map(int, input().split()))
a = []
for i in range(m):
    a.append(input().split())
haba = a[0]
for i in a:
    if int(haba[0]) <= int(i[0]) <= int(haba[1]):
        haba[0] = i[0]
    elif int(haba[1]) < int(i[0]):
        print((0))
        exit()
    if int(haba[0]) <= int(i[1]) <= int(haba[1]):
        haba[1] = i[1]
    elif int(i[1]) < int(haba[0]):
        print((0))
        exit()
if n < int(haba[0]):
    ans = 0
elif int(haba[0]) <= n <= int(haba[1]):
    ans = n - int(haba[0]) + 1
else:
    ans = int(haba[1]) - int(haba[0]) + 1
print(ans)

n, m = list(map(int, input().split()))
a = []
for i in range(m):
    a.append(list(map(int, input().split())))
haba = a[0]
for i in a:
    if haba[0] <= i[0] <= haba[1]:
        haba[0] = i[0]
    elif haba[1] < i[0]:
        print((0))
        exit()
    if haba[0] <= i[1] <= haba[1]:
        haba[1] = i[1]
    elif i[1] < haba[0]:
        print((0))
        exit()
if n < haba[0]:
    ans = 0
elif haba[0] <= n <= haba[1]:
    ans = n - haba[0] + 1
else:
    ans = haba[1] - haba[0] + 1
print(ans)

-    a.append(input().split()) +    a.append(list(map(int, input().split()))) -    if int(haba[0]) <= int(i[0]) <= int(haba[1]): +    if haba[0] <= i[0] <= haba[1]: -    elif int(haba[1]) < int(i[0]): +    elif haba[1] < i[0]: -    if int(haba[0]) <= int(i[1]) <= int(haba[1]): +    if haba[0] <= i[1] <= haba[1]: -    elif int(i[1]) < int(haba[0]): +    elif i[1] < haba[0]: -if n < int(haba[0]): +if n < haba[0]: -elif int(haba[0]) <= n <= int(haba[1]): -    ans = n - int(haba[0]) + 1 +elif haba[0] <= n <= haba[1]: +    ans = n - haba[0] + 1 -    ans = int(haba[1]) - int(haba[0]) + 1 +    ans = haba[1] - haba[0] + 1