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

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

c = Array.new(n + 2)
p = 0
t.each_with_index do |x, i|
  p += x
  c[i] = p
end

ans = 0
c.each do |x|
  ans += 1 if x == m
end

puts ans

