n,m=map(int,input().split())
l=0
r=99999999
for i in range(m):
  a,b=map(int,input().split())
  l=max(l,a)
  r=min(r,b)
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=0 l 0 r=99999999 r 99999999 for i in range(m):
  a,b=map(int,input().split())
  l=max(l,a)
  r=min(r,b) i range(m) range m a,b=map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b l=max(l,a) l max(l,a) max l a r=min(r,b) r min(r,b) min r b 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 a,b=map(int,input().split()) map(int,input().split()) a l=max(l,a) max(l,a) l r=99999999 99999999 r l=0 0 l m=map(int,input().split()) map(int,input().split()) m r=min(r,b) min(r,b) r b=map(int,input().split()) map(int,input().split()) b
n,m=map(int,input().split())
l=0
r=99999999
for i in range(m):
  a,b=map(int,input().split())
  l=max(l,a)
  r=min(r,b)
if r>=l:
  print(r-l+1)
else:
  print(0)
