nm = STDIN.gets.chomp.split(' ').map(&:to_i)

inputs = []

nm[1].times do
  inputs << STDIN.gets.chomp.split(' ').map(&:to_i)
end

low = inputs[0][0]
high = inputs[0][1]
inputs.each do |array|
  low = array[0] if low < array[0]
  high = array[1] if high > array[1]
end

puts [*low..high].length