n, m = gets.split.map(&:to_i)
lr = []
m.times do
  lr.push gets.split.map(&:to_i)
end

min = 0
max = 1000000

lr.each do |e|
  l = e.first
  r = e.last
  min = l if min < l
  max = r if max > r
end
puts [max - min + 1, 0].max
