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

ll = [list(map(int,input().split())) for _ in [0]*m]

l=[]

r=[]

for i in range(m):

  l.append(ll[i][0])

  r.append(ll[i][1])

l = max(l)

r = min(r)



  

#for _ in range(m):

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

#  l = max([a,l])

#  r = min([b,r])

print((max([0,r-l+1])))
n,m = list(map(int,input().split()))

#ll = [list(map(int,input().split())) for _ in [0]*m]

#l=[]

#r=[]

#for i in range(m):

#  l.append(ll[i][0])

#  r.append(ll[i][1])

#l = max(l)

#r = min(r)



l=0

r=n

for _ in range(m):

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

  l = l if l>a else a

  r = r if r<b else b

print((max([0,r-l+1])))
n, m = list(map(int, input().split()))
ll = [list(map(int, input().split())) for _ in [0] * m]
l = []
r = []
for i in range(m):
    l.append(ll[i][0])
    r.append(ll[i][1])
l = max(l)
r = min(r)
# for _ in range(m):
#  a,b = map(int,input().split())
#  l = max([a,l])
#  r = min([b,r])
print((max([0, r - l + 1])))

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

-ll = [list(map(int, input().split())) for _ in [0] * m] -l = [] -r = [] -for i in range(m): -    l.append(ll[i][0]) -    r.append(ll[i][1]) -l = max(l) -r = min(r) -# for _ in range(m): -#  a,b = map(int,input().split()) -#  l = max([a,l]) -#  r = min([b,r]) +# ll = [list(map(int,input().split())) for _ in [0]*m] +# l=[] +# r=[] +# for i in range(m): +#  l.append(ll[i][0]) +#  r.append(ll[i][1]) +# l = max(l) +# r = min(r) +l = 0 +r = n +for _ in range(m): +    a, b = list(map(int, input().split())) +    l = l if l > a else a +    r = r if r < b else b