n, m = gets.chomp.split(" ").map {|item| item.to_i }

max_l = 0
min_r = n


m.times do
    l, r = gets.chomp.split(" ").map {|item| item.to_i }
    if l > max_l
        max_l = l
    end
    if r < min_r
        min_r = r
    end
end

if (min_r - max_l) >= 0
    puts (min_r - max_l) + 1
else
    puts "0"
end