N, M = map(int, input().split())
L = []
R = []
for _ in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
max_L = max(L)
min_R = min(R)
ans = min_R - max_L + 1
if ans > 0:
    print(ans)
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 max_L = max(L) max_L max(L) max L min_R = min(R) min_R min(R) min R ans = min_R - max_L + 1 ans min_R - max_L + 1 min_R - max_L min_R max_L 1 if ans > 0:
    print(ans)
else:
    print(0) ans > 0 ans 0 print(ans) print ans print(0) print 0 L = [] [] L N, M = map(int, input().split()) map(int, input().split()) N l, r = map(int, input().split()) map(int, input().split()) l min_R = min(R) min(R) min_R ans = min_R - max_L + 1 min_R - max_L + 1 ans R = [] [] R M = map(int, input().split()) map(int, input().split()) M r = map(int, input().split()) map(int, input().split()) r max_L = max(L) max(L) max_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)
max_L = max(L)
min_R = min(R)
ans = min_R - max_L + 1
if ans > 0:
    print(ans)
else:
    print(0)
