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

c=list()



for i in range(m):

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



s=(list([x[0] for x in c]))

b=(list([x[1] for x in c]))



maxs=max(s)

minb=min(b)



if minb<maxs:

    print('0')

else:

    ans=minb-maxs+1

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

a=[]

b=[]

for i in range(m):

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

    a.append(l)

    b.append(r)

x=max(a)

y=min(b)



if y-x<0:

    print('0')

else:

    print((y-x+1))
n, m = list(map(int, input().split()))
c = list()
for i in range(m):
    c.append(list(map(int, input().split())))
s = list([x[0] for x in c])
b = list([x[1] for x in c])
maxs = max(s)
minb = min(b)
if minb < maxs:
    print("0")
else:
    ans = minb - maxs + 1
    print(ans)

n, m = list(map(int, input().split()))
a = []
b = []
for i in range(m):
    l, r = list(map(int, input().split()))
    a.append(l)
    b.append(r)
x = max(a)
y = min(b)
if y - x < 0:
    print("0")
else:
    print((y - x + 1))

-c = list() +a = [] +b = [] -    c.append(list(map(int, input().split()))) -s = list([x[0] for x in c]) -b = list([x[1] for x in c]) -maxs = max(s) -minb = min(b) -if minb < maxs: +    l, r = list(map(int, input().split())) +    a.append(l) +    b.append(r) +x = max(a) +y = min(b) +if y - x < 0: -    ans = minb - maxs + 1 -    print(ans) +    print((y - x + 1))