N,M = map(int,input().split())

bottom = 0
top = N+1

for i in range(M):
  L,R = map(int,input().split())
  bottom = max(bottom, L)
  top = min(top,R)
  
ans = top - bottom + 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 bottom = 0 bottom 0 top = N+1 top N+1 N 1 for i in range(M):
  L,R = map(int,input().split())
  bottom = max(bottom, L)
  top = min(top,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 bottom = max(bottom, L) bottom max(bottom, L) max bottom L top = min(top,R) top min(top,R) min top R ans = top - bottom + 1 ans top - bottom + 1 top - bottom top bottom 1 print(ans if ans>=0 else 0) print ans if ans>=0 else 0 ans>=0 ans 0 ans 0 bottom = 0 0 bottom bottom = max(bottom, L) max(bottom, L) bottom top = min(top,R) min(top,R) top R = map(int,input().split()) map(int,input().split()) R ans = top - bottom + 1 top - bottom + 1 ans L,R = map(int,input().split()) map(int,input().split()) L N,M = map(int,input().split()) map(int,input().split()) N M = map(int,input().split()) map(int,input().split()) M top = N+1 N+1 top
N,M = map(int,input().split())

bottom = 0
top = N+1

for i in range(M):
  L,R = map(int,input().split())
  bottom = max(bottom, L)
  top = min(top,R)
  
ans = top - bottom + 1
print(ans if ans>=0 else 0)