n, m = gets.chomp!.split(" ").map!(&:to_i)
l = Array.new(0, m)
r = Array.new(0, m)
m.times do |i|
    l[i], r[i] = gets.chomp!.split(" ").map!(&:to_i)
end

=begin
memo = {}
n.times do |i|
    memo[i] = i
end

m.times do |i|
    l[i].upto(r[i]) do |j|
end

puts x.count
=end

tmp = (r.min - l.max) + 1
puts tmp > 0 ? tmp : 0
