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

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

sum = 0
ans = 0
n.times do |i|
  sum += a[i+1]
  ans += 1 if sum == m
end

puts ans
