n,m = gets.split.map(&:to_i)
ls = m.times.map{gets.split.map(&:to_i)}

a = [ls[0][0],ls[0][1]]

ls.each do |b|
  if a[0] < b[0]
    a[0] = b[0]
  end
  if a[1] > b[1]
    a[1] = b[1]
  end
end

tmp = a[1] - a[0]
if tmp < 0
  puts 0
else
  puts tmp + 1
end
