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