n, m = gets.chomp.split.map(&:to_i)

list = Array.new(n+2, 0)
m.times do |i|
  l, r = gets.chomp.split.map(&:to_i)
  list[l] += 1
  list[r+1] -= 1
end

sum = [0]
count = 0
(1..n).each do |i|
  sum[i] = sum[i-1] + list[i]
  count += 1 if sum[i] == m
end

puts(count)