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