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

L_list = []
R_list = []

for i in range(M):
    A, B = map(int, input().split())
    L_list.append(A)
    R_list.append(B)

if max(L_list) > min(R_list):
    print(0)
else:
    print(min(R_list) - max(L_list) + 1) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L_list = [] L_list [] R_list = [] R_list [] for i in range(M):
    A, B = map(int, input().split())
    L_list.append(A)
    R_list.append(B) i range(M) range M A, B = map(int, input().split()) A map(int, input().split()) map int input().split() ().split () input split B L_list.append(A) L_list.append L_list append A R_list.append(B) R_list.append R_list append B if max(L_list) > min(R_list):
    print(0)
else:
    print(min(R_list) - max(L_list) + 1) max(L_list) > min(R_list) max(L_list) max L_list min(R_list) min R_list print(0) print 0 print(min(R_list) - max(L_list) + 1) print min(R_list) - max(L_list) + 1 min(R_list) - max(L_list) min(R_list) min R_list max(L_list) max L_list 1 L_list = [] [] L_list M = map(int, input().split()) map(int, input().split()) M R_list = [] [] R_list N, M = map(int, input().split()) map(int, input().split()) N B = map(int, input().split()) map(int, input().split()) B A, B = map(int, input().split()) map(int, input().split()) A
N, M = map(int, input().split())

L_list = []
R_list = []

for i in range(M):
    A, B = map(int, input().split())
    L_list.append(A)
    R_list.append(B)

if max(L_list) > min(R_list):
    print(0)
else:
    print(min(R_list) - max(L_list) + 1)