n, m = gets.strip.split.map(&:to_i)
l = []
r = []

m.times do
  a, b = gets.strip.split.map(&:to_i)
  l << a
  r << b
end

min = 1
max = n

m.times do |i|
  if l[i] > min
    min = l[i]
  end
  if r[i] < max
    max = r[i]
  end
end

result = max - min + 1
if result < 0
  result = 0
end
puts result