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

lrl = list(list(map(int, input().split())) for _ in range(m))

lmax = 0

rmin = n



for lr in lrl:

    if lr[0] > lmax:

        lmax = lr[0]

    if lr[1] < rmin:

        rmin = lr[1]

if lmax <= rmin:

    print((rmin-lmax+1))

else:

    print((0))







import numpy as np

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

ans = [0]*n



for _ in range(m):

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

    ans[l-1] += 1

    if r < n:

        ans[r] -= 1



c = list(np.cumsum(ans))

print((c.count(m)))
n, m = list(map(int, input().split()))
lrl = list(list(map(int, input().split())) for _ in range(m))
lmax = 0
rmin = n
for lr in lrl:
    if lr[0] > lmax:
        lmax = lr[0]
    if lr[1] < rmin:
        rmin = lr[1]
if lmax <= rmin:
    print((rmin - lmax + 1))
else:
    print((0))

import numpy as np

n, m = list(map(int, input().split()))
ans = [0] * n
for _ in range(m):
    l, r = list(map(int, input().split()))
    ans[l - 1] += 1
    if r < n:
        ans[r] -= 1
c = list(np.cumsum(ans))
print((c.count(m)))

+import numpy as np + -lrl = list(list(map(int, input().split())) for _ in range(m)) -lmax = 0 -rmin = n -for lr in lrl: -    if lr[0] > lmax: -        lmax = lr[0] -    if lr[1] < rmin: -        rmin = lr[1] -if lmax <= rmin: -    print((rmin - lmax + 1)) -else: -    print((0)) +ans = [0] * n +for _ in range(m): +    l, r = list(map(int, input().split())) +    ans[l - 1] += 1 +    if r < n: +        ans[r] -= 1 +c = list(np.cumsum(ans)) +print((c.count(m)))