import sys
n = int(raw_input())
e = [[int(i) for i in raw_input().split()] for i in range(n)]
m = n
li = []
for i in range(n):
    for j in range(i, n):
        if i == j: continue
        li.append(min(abs(e[i][0] - e[j][0]), abs(e[i][1] - e[j][1])))
li.sort()
ans = 0
for i in range(n-1):
    ans += li[i]
print ans