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

ids = []
m.times do
  l, r = gets.chomp.split(' ').map(&:to_i)
  ids << (l..r).to_a
end

common = ids.shift
while id = ids.shift
  common = common & id
end

puts common.count