N,M = gets.chomp.split.map(&:to_i)
conds = []
M.times do 
	conds << gets.chomp.split.map(&:to_i)
end
  
l,r = conds[0][0],conds[0][1]

conds.each{|cond|
  l = cond[0] if l < cond[0]
  r = cond[1] if r > cond[1]
}

result = r - l + 1
ans =  result > 0 ? result : 0
puts ans