n, m = gets.chomp.split.map(&:to_i)
max_l = 0
min_r = 10**5
for i in 0..(m - 1) do
  l, r = gets.chomp.split.map(&:to_i)
  max_l = l if max_l < l
  min_r = r if min_r > r
end

if min_r - max_l >= 0
  card = min_r - max_l + 1
else
  card = 0
end
print("#{card}\n")