#!/user/bin/env ruby

N, M = gets.chomp.split.map(&:to_i)

a = []
while line = gets do
  a << line.chomp.split.map(&:to_i)
end
# p a

min = 0
max = N

a.each do |item|
  if min < item[0] then
    min = item[0]
  end

  if max > item[1] then
    max = item[1]
  end
end

puts 1 + max - min
