_n,m = gets.split(' ').map(&:to_i)
l = []
r = []
m.times do |a|
    single_l,single_r = gets.split(' ').map(&:to_i)
    l << single_l
    r << single_r
end
array = (l.max..r.min).to_a
puts array.length
