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

li=[]

for i in range(m):

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

    li.append(a)

l=0

r=n

for i in range(m):

    if li[i][0]>l:

        l=li[i][0]

    if li[i][1]<r:

        r=li[i][1]

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

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

L=[]

R=[]

for i in range(m):

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

    L.append(l)

    R.append(r)

a=max(L)

b=min(R)

li=[i for i in range(a,b+1)]

print((len(li)))



n, m = list(map(int, input().split()))
li = []
for i in range(m):
    a = list(map(int, input().split()))
    li.append(a)
l = 0
r = n
for i in range(m):
    if li[i][0] > l:
        l = li[i][0]
    if li[i][1] < r:
        r = li[i][1]
print((max(0, r - l + 1)))

n, m = list(map(int, input().split()))
L = []
R = []
for i in range(m):
    l, r = list(map(int, input().split()))
    L.append(l)
    R.append(r)
a = max(L)
b = min(R)
li = [i for i in range(a, b + 1)]
print((len(li)))

-li = [] +L = [] +R = [] -    a = list(map(int, input().split())) -    li.append(a) -l = 0 -r = n -for i in range(m): -    if li[i][0] > l: -        l = li[i][0] -    if li[i][1] < r: -        r = li[i][1] -print((max(0, r - l + 1))) +    l, r = list(map(int, input().split())) +    L.append(l) +    R.append(r) +a = max(L) +b = min(R) +li = [i for i in range(a, b + 1)] +print((len(li)))