N,M = map(int, input().split())
l=0
r=N
for _ in range(M):
  ll,rr=map(int,input().split())
  l = max(l,ll)
  r = min(r,rr)
ans = r - l + 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 l=0 l 0 r=N r N for _ in range(M):
  ll,rr=map(int,input().split())
  l = max(l,ll)
  r = min(r,rr) _ range(M) range M ll,rr=map(int,input().split()) ll map(int,input().split()) map int input().split() ().split () input split rr l = max(l,ll) l max(l,ll) max l ll r = min(r,rr) r min(r,rr) min r rr ans = r - l + 1 ans r - l + 1 r - l r l 1 print(ans if ans > 0 else 0) print ans if ans > 0 else 0 ans > 0 ans 0 ans 0 r = min(r,rr) min(r,rr) r M = map(int, input().split()) map(int, input().split()) M ans = r - l + 1 r - l + 1 ans r=N N r ll,rr=map(int,input().split()) map(int,input().split()) ll l=0 0 l rr=map(int,input().split()) map(int,input().split()) rr l = max(l,ll) max(l,ll) l N,M = map(int, input().split()) map(int, input().split()) N
N,M = map(int, input().split())
l=0
r=N
for _ in range(M):
  ll,rr=map(int,input().split())
  l = max(l,ll)
  r = min(r,rr)
ans = r - l + 1
print(ans if ans > 0 else 0)