line = gets.chomp
n,m = line.split.map(&:to_i)


min = 1
max = n
while a = gets do
  a = a.chomp.split.map(&:to_i)
  id_arr = id_arr & (a[0]..a[1]).to_a
  min = [min,a[0]].max
  max = [max,a[1]].min
end

puts max - min + 1