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