n, m = gets.chomp.split.map(&:to_i)
gate = []
for i in 0..(m -1) do
  l, r = gets.chomp.split.map(&:to_i)
  if i == 0
    gate = (l..r).to_a
  else
    gate = gate & (l..r).to_a
  end
end

print("#{gate.length}\n")