a, b = gets.split(" ").map(&:to_i)
array = []
result = nil
b.times {|i| array << gets.split(" ").map(&:to_i)}
array.each.with_index do |x, i|
  if i == 0
    result = (x[0]..x[1]).to_a
  else
    result = result & (x[0]..x[1]).to_a
  end
end
puts result.length