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!
result = []
(l.max..r.min).each do |i|
  result << i
end

puts result.size