n = int(input())

cords = dict()
min_x = float("inf")
max_x = float("-inf")
xs = []

for i in range(n):
    x, y = tuple(map(int, input().split()))
    min_x = min(x, min_x)
    max_x = max(x, max_x)

    if x not in cords.keys():
        xs.append(x)
        cords[x] = {
            "min": y,
            "max": y,
        }
    else:
        cords[x]["min"] = min(cords[x]["min"], y)
        cords[x]["max"] = max(cords[x]["max"], y)

dist = max_x - min_x
xs.sort()
dp = dict()
dp[xs[-1]] = {
    "D": cords[xs[-1]]["max"] - cords[xs[-1]]["min"],
    "H": cords[xs[-1]]["max"] - cords[xs[-1]]["min"]
}

for i in reversed(range(len(xs))):
    if i == len(xs) - 1:
        continue
    dp[xs[i]] = dict()
    dp[xs[i]]["D"] = min(dp[xs[i + 1]]["D"] + abs(cords[xs[i]]["max"] - cords[xs[i + 1]]["min"]),
                         dp[xs[i + 1]]["H"] + abs(cords[xs[i]]["max"] - cords[xs[i + 1]]["max"])) + cords[
                         xs[i]]["max"] - cords[xs[i]]["min"]
    dp[xs[i]]["H"] = min(dp[xs[i + 1]]["D"] + abs(cords[xs[i]]["min"] - cords[xs[i + 1]]["min"]),
                         dp[xs[i + 1]]["H"] + abs(cords[xs[i]]["min"] - cords[xs[i + 1]]["max"])) + cords[
                         xs[i]]["max"] - cords[xs[i]]["min"]

dist += min(dp[xs[0]]["D"], dp[xs[0]]["H"])

print(dist)
