n,m = gets.split.map(&:to_i)
min = -1
max = -1
m.times do
  l,r=gets.split.map(&:to_i)
  if min == -1 && max == -1
  	min,max = l,r
  else
    min = l if min < l
  	max = r if max > r
  end
end
result = max - min + 1
puts result < 0 ? 0 : result