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.size-1).times do |i|
    arr =  n[i, 2]
    r = [*arr[0][0]..arr[0][1]] & [*arr[1][0]..arr[1][1]]
    result = result & r
  end
else
  result = [*n[0][0]..n[0][1]]
end

p result.size