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

result = []
if n.size > 1
  (n.size-1).times do |i|
    arr =  n[i, 2]
    first =  [*arr[0][0]..arr[0][1]]
    second =  [*arr[1][0]..arr[1][1]]
    r = first & second
    result = r if i == 0
    result = result & r
  end
else # n.size == 1
  result = [*n[0][0]..n[0][1]]
end

p result.size