n,m = gets.split(' ').map(&:to_i)
min_limit = 1
max_limit = n
(0...m).each do |i|
  gate_info = gets.split(' ').map(&:to_i)
  min_limit = gate_info[0] if gate_info[0] > min_limit
  max_limit = gate_info[1] if gate_info[1] < max_limit
end
puts [max_limit - min_limit + 1, 0].max
