n = gets.split.map(&:to_i)
gate = [1,n[0]]
for i in 0..n[1]-1
  inst = gets.split.map(&:to_i)
  if inst[0] > gate[0]
    gate[0] = inst[0]
  end
  if inst[1] < gate[1]
    gate[1] = inst[1]
  end
end
puts [gate[1]-gate[0]+1,0].max
