nm=gets.chomp.split(" ").map(&:to_i)
lr=[]
nm[1].times do|i|
	lr[i]=gets.chomp.split(" ").map(&:to_i)
end
min=lr[0][0]
max=lr[0][1]
for i in 1..nm[1]-1
	if(min<lr[i][0])
		min=lr[i][0]
	end
	if(max>lr[i][1])
		max=lr[i][1]
	end
end
puts max-min+1