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