N,M = map(int,input().split())
min_i = 0
max_i = N+1
for _ in range(M):
  a,b = map(int,input().split())
  min_i = max(min_i,a)
  max_i = min(max_i,b+1)
  
c = max(max_i - min_i,0)
print(c) N,M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M min_i = 0 min_i 0 max_i = N+1 max_i N+1 N 1 for _ in range(M):
  a,b = map(int,input().split())
  min_i = max(min_i,a)
  max_i = min(max_i,b+1)
   _ range(M) range M a,b = map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b min_i = max(min_i,a) min_i max(min_i,a) max min_i a max_i = min(max_i,b+1) max_i min(max_i,b+1) min max_i b+1 b 1 c = max(max_i - min_i,0) c max(max_i - min_i,0) max max_i - min_i max_i min_i 0 print(c) print c min_i = 0 0 min_i max_i = N+1 N+1 max_i max_i = min(max_i,b+1) min(max_i,b+1) max_i min_i = max(min_i,a) max(min_i,a) min_i b = map(int,input().split()) map(int,input().split()) b a,b = map(int,input().split()) map(int,input().split()) a M = map(int,input().split()) map(int,input().split()) M N,M = map(int,input().split()) map(int,input().split()) N c = max(max_i - min_i,0) max(max_i - min_i,0) c
N,M = map(int,input().split())
min_i = 0
max_i = N+1
for _ in range(M):
  a,b = map(int,input().split())
  min_i = max(min_i,a)
  max_i = min(max_i,b+1)
  
c = max(max_i - min_i,0)
print(c)
