N, M = map(int, input().split())
maxL = 0
minR = N-1
LR = [0, N-1]
for i in range(M):
  LR = [int(i)-1 for i in input().split()]
  maxL = max(maxL, LR[0])
  minR = min(minR, LR[1])
if minR-maxL>=0:
  print(minR-maxL+1)
else:
  print(0) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M maxL = 0 maxL 0 minR = N-1 minR N-1 N 1 LR = [0, N-1] LR [0, N-1] 0 N-1 N 1 for i in range(M):
  LR = [int(i)-1 for i in input().split()]
  maxL = max(maxL, LR[0])
  minR = min(minR, LR[1]) i range(M) range M int(i)-1 for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i)-1 int(i) int i 1 LR = [int(i)-1 for i in input().split()] LR [int(i)-1 for i in input().split()] maxL = max(maxL, LR[0]) maxL max(maxL, LR[0]) max maxL LR[0] LR 0 minR = min(minR, LR[1]) minR min(minR, LR[1]) min minR LR[1] LR 1 if minR-maxL>=0:
  print(minR-maxL+1)
else:
  print(0) minR-maxL>=0 minR-maxL minR maxL 0 print(minR-maxL+1) print minR-maxL+1 minR-maxL minR maxL 1 print(0) print 0 maxL = max(maxL, LR[0]) max(maxL, LR[0]) maxL minR = min(minR, LR[1]) min(minR, LR[1]) minR M = map(int, input().split()) map(int, input().split()) M minR = N-1 N-1 minR LR = [int(i)-1 for i in input().split()] [int(i)-1 for i in input().split()] LR maxL = 0 0 maxL LR = [0, N-1] [0, N-1] LR N, M = map(int, input().split()) map(int, input().split()) N
N, M = map(int, input().split())
maxL = 0
minR = N-1
LR = [0, N-1]
for i in range(M):
  LR = [int(i)-1 for i in input().split()]
  maxL = max(maxL, LR[0])
  minR = min(minR, LR[1])
if minR-maxL>=0:
  print(minR-maxL+1)
else:
  print(0)
