N, M = gets.split.map &:to_i
l, r = gets.split.map &:to_i
min = l
max = r
(M-1).times do
  l, r = gets.split.map &:to_i
  min = l if min < l
  max = r if max > r
end

if N < min
  puts 0
elsif N < max
  puts N - min + 1
else
  puts max - min + 1
end