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

for i in range(M):
  L, R = map(int, input().split())
  
  if i == 0:
    top = R
    bottom = L
  
  top = min(top, R)
  bottom = max(bottom, L)

if top >= bottom:
  print(top-bottom+1)
else:
  print(0) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M for i in range(M):
  L, R = map(int, input().split())
  
  if i == 0:
    top = R
    bottom = L
  
  top = min(top, R)
  bottom = max(bottom, L) i range(M) range M L, R = map(int, input().split()) L map(int, input().split()) map int input().split() ().split () input split R if i == 0:
    top = R
    bottom = L
  
   i == 0 i 0 top = R top R bottom = L bottom L top = min(top, R) top min(top, R) min top R bottom = max(bottom, L) bottom max(bottom, L) max bottom L if top >= bottom:
  print(top-bottom+1)
else:
  print(0) top >= bottom top bottom print(top-bottom+1) print top-bottom+1 top-bottom top bottom 1 print(0) print 0 R = map(int, input().split()) map(int, input().split()) R N, M = map(int, input().split()) map(int, input().split()) N top = min(top, R) min(top, R) top bottom = L L bottom bottom = max(bottom, L) max(bottom, L) bottom top = R R top M = map(int, input().split()) map(int, input().split()) M L, R = map(int, input().split()) map(int, input().split()) L
N, M = map(int, input().split())

for i in range(M):
  L, R = map(int, input().split())
  
  if i == 0:
    top = R
    bottom = L
  
  top = min(top, R)
  bottom = max(bottom, L)

if top >= bottom:
  print(top-bottom+1)
else:
  print(0)