n,m=map(int,input().split())
a=[]
for x in range(m):
  s=list(map(int,input().split()))
  a.append(s)
  
min1=1
max1=n

for y in range(m):
  l=a[y][0]
  r=a[y][1]
  if min1<l:
    min1=l
  if max1>r:
    max1=r
    
if max1-min1>=0:
  print(max1-min1+1)
  
else:
  print(0) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m a=[] a [] for x in range(m):
  s=list(map(int,input().split()))
  a.append(s)
   x range(m) range m s=list(map(int,input().split())) s list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split a.append(s) a.append a append s min1=1 min1 1 max1=n max1 n for y in range(m):
  l=a[y][0]
  r=a[y][1]
  if min1<l:
    min1=l
  if max1>r:
    max1=r
     y range(m) range m l=a[y][0] l a[y][0] [y] a y 0 r=a[y][1] r a[y][1] [y] a y 1 if min1<l:
    min1=l
   min1<l min1 l min1=l min1 l if max1>r:
    max1=r
     max1>r max1 r max1=r max1 r if max1-min1>=0:
  print(max1-min1+1)
  
else:
  print(0) max1-min1>=0 max1-min1 max1 min1 0 print(max1-min1+1) print max1-min1+1 max1-min1 max1 min1 1 print(0) print 0 a=[] [] a s=list(map(int,input().split())) list(map(int,input().split())) s max1=r r max1 l=a[y][0] a[y][0] l r=a[y][1] a[y][1] r max1=n n max1 min1=l l min1 min1=1 1 min1 m=map(int,input().split()) map(int,input().split()) m n,m=map(int,input().split()) map(int,input().split()) n
n,m=map(int,input().split())
a=[]
for x in range(m):
  s=list(map(int,input().split()))
  a.append(s)
  
min1=1
max1=n

for y in range(m):
  l=a[y][0]
  r=a[y][1]
  if min1<l:
    min1=l
  if max1>r:
    max1=r
    
if max1-min1>=0:
  print(max1-min1+1)
  
else:
  print(0)