n, m = map(int, input().split())
l = 1
r = 10**5
for _ in range(m):
  l_, r_ = map(int, input().split())
  l = max(l, l_)
  r = min(r, r_)
  
if r>=l:
  print(r-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 = 1 l 1 r = 10**5 r 10**5 10 5 for _ in range(m):
  l_, r_ = map(int, input().split())
  l = max(l, l_)
  r = min(r, r_)
   _ range(m) range m l_, r_ = map(int, input().split()) l_ map(int, input().split()) map int input().split() ().split () input split r_ l = max(l, l_) l max(l, l_) max l l_ r = min(r, r_) r min(r, r_) min r r_ if r>=l:
  print(r-l+1)
else:
  print(0) r>=l r l print(r-l+1) print r-l+1 r-l r l 1 print(0) print 0 n, m = map(int, input().split()) map(int, input().split()) n l = max(l, l_) max(l, l_) l r = 10**5 10**5 r l_, r_ = map(int, input().split()) map(int, input().split()) l_ r_ = map(int, input().split()) map(int, input().split()) r_ m = map(int, input().split()) map(int, input().split()) m r = min(r, r_) min(r, r_) r l = 1 1 l
n, m = map(int, input().split())
l = 1
r = 10**5
for _ in range(m):
  l_, r_ = map(int, input().split())
  l = max(l, l_)
  r = min(r, r_)
  
if r>=l:
  print(r-l+1)
else:
  print(0)