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