N,M = gets.split(" ").map{|e| e.to_i}
tmp = gets.split(" ").map{|e| e.to_i}
min = tmp[0]
max = tmp[1]
(M-1).times do
  tmp = gets.split(" ").map{|e| e.to_i}
  if min < tmp[0]
    min = tmp[0]
  end
  if max > tmp[1]
    max = tmp[1]
  end
end
puts (min..max).to_a.size