n,m = map(int,input().split())
L = [0]*m; R = [0]*m; cnt = 0
for i in range(m):
    L[i],R[i] = map(int,input().split())
ml = max(L); mr = min(R)
print(mr-ml+1) if ml <= mr else print(0) n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m L = [0]*m L [0]*m [0] 0 m R = [0]*m R [0]*m [0] 0 m cnt = 0 cnt 0 for i in range(m):
    L[i],R[i] = map(int,input().split()) i range(m) range m L[i],R[i] = map(int,input().split()) L[i] L i map(int,input().split()) map int input().split() ().split () input split R[i] R i ml = max(L) ml max(L) max L mr = min(R) mr min(R) min R print(mr-ml+1) if ml <= mr else print(0) ml <= mr ml mr print(mr-ml+1) print mr-ml+1 mr-ml mr ml 1 print(0) print 0 R = [0]*m [0]*m R n,m = map(int,input().split()) map(int,input().split()) n L = [0]*m [0]*m L mr = min(R) min(R) mr m = map(int,input().split()) map(int,input().split()) m cnt = 0 0 cnt ml = max(L) max(L) ml
n,m = map(int,input().split())
L = [0]*m; R = [0]*m; cnt = 0
for i in range(m):
    L[i],R[i] = map(int,input().split())
ml = max(L); mr = min(R)
print(mr-ml+1) if ml <= mr else print(0)