N,M = map(int,input().split())
L = []
R = []
for _ in range(M):
    a,b = map(int,input().split())
    L.append(a)
    R.append(b)

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

if min(R) - max(L) >= 0:
    print(min(R) - max(L) + 1)
else:
    print(0)