n, m = gets.chomp.split.map(&:to_i)
l = []
r = []
m.times do |i|
  l[i], r[i] = gets.chomp.split.map(&:to_i)
end

array = (l[0]..r[0]).to_a
1.upto(m-1) do |i|
  next_array = (l[i]..r[i]).to_a
  array = array & next_array
end
p array.size
