n,m=map(int,input().split())
low=1
high=n 
for _ in range(m):
    l,r=map(int,input().split())
    low=max(l,low)
    high=min(r,high)
if high-low+1>=0:
    print(high-low+1)
else:
  print(0) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m low=1 low 1 high=n high n for _ in range(m):
    l,r=map(int,input().split())
    low=max(l,low)
    high=min(r,high) _ range(m) range m l,r=map(int,input().split()) l map(int,input().split()) map int input().split() ().split () input split r low=max(l,low) low max(l,low) max l low high=min(r,high) high min(r,high) min r high if high-low+1>=0:
    print(high-low+1)
else:
  print(0) high-low+1>=0 high-low+1 high-low high low 1 0 print(high-low+1) print high-low+1 high-low high low 1 print(0) print 0 low=1 1 low m=map(int,input().split()) map(int,input().split()) m r=map(int,input().split()) map(int,input().split()) r low=max(l,low) max(l,low) low n,m=map(int,input().split()) map(int,input().split()) n high=min(r,high) min(r,high) high high=n n high l,r=map(int,input().split()) map(int,input().split()) l
n,m=map(int,input().split())
low=1
high=n 
for _ in range(m):
    l,r=map(int,input().split())
    low=max(l,low)
    high=min(r,high)
if high-low+1>=0:
    print(high-low+1)
else:
  print(0)