def kyori(n,m)
	return $memo[n][m] if !$memo[n][m].nil?
	$memo[n][m] = $memo[m][n] = [($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 == []
	min = Float::INFINITY
	candidate = []
	a.each do |aa|
		b.each do |bb|
			if kyori(aa, bb) < min
				min = kyori(aa, bb)
				candidate = [aa, bb]
			end
		end
	end
	kekka = []
	mincost(a +  [candidate[1]], b -  [candidate[1]], cost + kyori(candidate[0], candidate[1]))
end

N = gets.to_i
$memo = []
N.times do |i|
	$memo[i] = []
end
$xy = []
N.times do
	$xy << gets.split(" ").map(&:to_i)
end
a = [0]
b = (1..(N-1)).to_a

puts mincost(a, b, 0)