n,m = gets.split.map(&:to_i)
l = []
r = []
m.times do
  line = gets.split.map(&:to_i)
  l << line.shift
  r << line
end
r.flatten!
array = []

(0...m).each do |i|
  array << (l[i]..r[i]).to_a
end

puts array.flatten.select{|e|array.count(e) > m - 1}.uniq.size
