def merge_ranges(a, b)
  [a.begin, b.begin].max..[a.end, b.end].min
end

nm = gets.chomp.split(" ")
n = nm[0].to_i
m = nm[1].to_i

gate_ranges = []
m.times.each do
  lr = gets.chomp.split(" ")
  gate_ranges << ((lr[0].to_i)..(lr[1].to_i))
end

ans_range = gate_ranges[0]
gate_ranges.each do |range|
  ans_range = merge_ranges(ans_range, range)
end

puts ans_range.count