n, m = gets.chomp.split(' ').map(&:to_i)
lrs = m.times.map { gets.chomp.split(' ').map(&:to_i) }

min_n = 1
max_n = n
lrs.each do |l, r|
    min_n = [l, min_n].max
    max_n = [r, max_n].min
end

puts (min_n..max_n).count
