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

li = []
ri = []

for i in 0...M do
  l, r = gets.chomp.split(" ").map(&:to_i)
  li[i] = l
  ri[i] = r
end

# liの最大値 - riの最小値が答え

if (ri.min - li.max) >= 0 then
  puts ri.min - li.max + 1
else
  puts 0
end
