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

l=[list(map(int,input().split())) for i in range(m)]

L=[]

R=[]

for i in range(m):

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

  R.append(l[i][1])

print((max(min(R)-max(L)+1,0)))
# coding: utf-8

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

r = float('inf')

l = 0

L = []

for i in range(m):

    l_, r_ = list(map(int,input().split()))

    L.append([l_,r_])

    l = max(l_, l)

    r = min(r_, r)

ans = 0

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

# coding: utf-8
n, m = list(map(int, input().split()))
r = float("inf")
l = 0
L = []
for i in range(m):
    l_, r_ = list(map(int, input().split()))
    L.append([l_, r_])
    l = max(l_, l)
    r = min(r_, r)
ans = 0
print((max(0, r - l + 1)))

+# coding: utf-8 -l = [list(map(int, input().split())) for i in range(m)] +r = float("inf") +l = 0 -R = [] -    L.append(l[i][0]) -    R.append(l[i][1]) -print((max(min(R) - max(L) + 1, 0))) +    l_, r_ = list(map(int, input().split())) +    L.append([l_, r_]) +    l = max(l_, l) +    r = min(r_, r) +ans = 0 +print((max(0, r - l + 1)))