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