N, M = gets.split(' ').map(&:to_i)
prev_l, prev_r = 1, 100000
M.times do
  l, r = gets.split(' ').map(&:to_i)
  prev_l = l if l > prev_l
  prev_r = r if r < prev_r
end
puts (prev_l <= prev_r) ? (prev_r - prev_l + 1) : 0 