def kyori(n,m)
	return $memo[n][m] if !$memo[n][m].nil?
	$memo[n][m] = [($xy[n][0] - $xy[m][0]).abs, ($xy[n][1] - $xy[m][1]).abs].min
end

def mincost(a, b, cost)
	return cost if b == []
	candidate = []
	min = Float::INFINITY
	a.each do |aa|
		b.each do |bb|
			if kyori(aa, bb) < min
				min = kyori(aa, bb)
				candidate = [[aa, bb]]
			else kyori(aa, bb) == min
				candidate << [aa, bb]
			end
		end
	end
	total_min = Float::INFINITY
	kekka = []
	candidate.each do |cand|
		kekka << mincost(a + [cand[1]], b - [cand[1]], cost + kyori(cand[0], cand[1]))
	end
	kekka
end

N = gets.to_i
$xy = []
N.times do
	$xy << gets.split(" ").map(&:to_i)
end

a = [0]
b = (1..(N-1)).to_a

puts mincost(a, b, 0).flatten.min
