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

l,r=1,n

for i in range(m):

    a,b=list(map(int,input().split()))

    l=max(l,a)

    r=min(r,b)

print((r-l+1 if r>=l else 0))
n,m,*a=list(map(int,open(0).read().split()))

b=min(a[1::2])-max(a[::2])+1

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

n, m, *a = list(map(int, open(0).read().split()))
b = min(a[1::2]) - max(a[::2]) + 1
print((b if b > 0 else 0))

-n, m = list(map(int, input().split())) -l, r = 1, n -for i in range(m): -    a, b = list(map(int, input().split())) -    l = max(l, a) -    r = min(r, b) -print((r - l + 1 if r >= l else 0)) +n, m, *a = list(map(int, open(0).read().split())) +b = min(a[1::2]) - max(a[::2]) + 1 +print((b if b > 0 else 0))