N, M = gets.split.map(&:to_i)

gate = M.times.map { gets.split.map(&:to_i) }

counter = Array.new(N + 2, 0)

gate.each do |l, r|
  counter[l] += 1
  counter[r + 1] -= 1
end

ans = 0

cnt = 0

(1..N).each do |i|
  cnt += counter[i]

  if cnt == M
    ans += 1
  end
end

puts ans
