n,m = map(int, input().split())
x = []
y = []
for _ in range(m):
  l,r = map(int, input().split())
  x.append(l)
  y.append(r)
x = max(x)
y = min(y)

if y-x >= 0: print(y-x+1)
else: print(0) n,m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m x = [] x [] y = [] y [] for _ in range(m):
  l,r = map(int, input().split())
  x.append(l)
  y.append(r) _ range(m) range m l,r = map(int, input().split()) l map(int, input().split()) map int input().split() ().split () input split r x.append(l) x.append x append l y.append(r) y.append y append r x = max(x) x max(x) max x y = min(y) y min(y) min y if y-x >= 0: print(y-x+1)
else: print(0) y-x >= 0 y-x y x 0 y = min(y) min(y) y r = map(int, input().split()) map(int, input().split()) r x = [] [] x y = [] [] y n,m = map(int, input().split()) map(int, input().split()) n x = max(x) max(x) x l,r = map(int, input().split()) map(int, input().split()) l m = map(int, input().split()) map(int, input().split()) m
n,m = map(int, input().split())
x = []
y = []
for _ in range(m):
  l,r = map(int, input().split())
  x.append(l)
  y.append(r)
x = max(x)
y = min(y)

if y-x >= 0: print(y-x+1)
else: print(0)