N, M = gets.split(" ").map(&:to_i)
l=[]; r = []
M.times do |i|
  l[i], r[i] = gets.split(" ").map(&:to_i)
end
lt = l[0]; rt = r[0]
1.upto(M-1) do |i|
  if l[i] > lt
    lt = l[i]
  end
  if r[i] < rt
    rt = r[i]
  end
end
rslt = rt - lt + 1
if rslt > 0
  puts rslt
else
  puts 0
end