n, m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(m)]

L = []
R = []
L_append = L.append
R_append = R.append
for l, r in LR:
    L.append(l)
    R.append(r)

min_R = min(R)
max_L = max(L)
if min_R >= max_L:
  ans = min_R +1 - max_L
else:
  ans = 0
  
print(ans) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split LR = [list(map(int, input().split())) for _ in range(m)] LR [list(map(int, input().split())) for _ in range(m)] L = [] L [] R = [] R [] L_append = L.append L_append L.append L append R_append = R.append R_append R.append R append for l, r in LR:
    L.append(l)
    R.append(r) l r LR L.append(l) L.append L append l R.append(r) R.append R append r min_R = min(R) min_R min(R) min R max_L = max(L) max_L max(L) max L if min_R >= max_L:
  ans = min_R +1 - max_L
else:
  ans = 0
   min_R >= max_L min_R max_L ans = min_R +1 - max_L ans min_R +1 - max_L min_R +1 min_R 1 max_L ans = 0 ans 0 print(ans) print ans L_append = L.append L.append L_append min_R = min(R) min(R) min_R m = map(int, input().split()) map(int, input().split()) m R_append = R.append R.append R_append L = [] [] L R = [] [] R ans = 0 0 ans max_L = max(L) max(L) max_L n, m = map(int, input().split()) map(int, input().split()) n LR = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] LR ans = min_R +1 - max_L min_R +1 - max_L ans
n, m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(m)]

L = []
R = []
L_append = L.append
R_append = R.append
for l, r in LR:
    L.append(l)
    R.append(r)

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