card, gate = gets.split.map(&:to_i)
n = []
gate.times do
  n << gets.split.map(&:to_i)
end

result = [*1..card]
if n.size > 1
  n.each do |n|
    r = [*n[0]..n[1]]
    result = result & r
  end
else
  result = [*n[0][0]..n[0][1]]
end
p result.size