N,M = list(map(int, input().split()))

L,R = [],[]

for _ in range(M):

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

    L.append(l)

    R.append(r)

print((max(min(R)-max(L)+1,0)))
import sys

N,M = list(map(int, input().split()))

D = sys.stdin

L = []

R = []

for d in D:

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

    L.append(l)

    R.append(r)

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

import sys

N, M = list(map(int, input().split()))
D = sys.stdin
L = []
R = []
for d in D:
    l, r = list(map(int, d.split()))
    L.append(l)
    R.append(r)
print((max(min(R) - max(L) + 1, 0)))

+import sys + -L, R = [], [] -for _ in range(M): -    l, r = list(map(int, input().split())) +D = sys.stdin +L = [] +R = [] +for d in D: +    l, r = list(map(int, d.split()))