import sys

if __name__ == '__main__':
    N = int(sys.stdin.readline().strip("\n"))
    data = dict()
    for _ in range(N):
        x, y = sys.stdin.readline().strip("\n").split()
        x, y = int(x), int(y)
        if x in data:
            mi, ma = data[x]
            data[x] = (min(mi, y), max(ma, y))
        else:
            data[x] = (y, y)
    axis = sorted(data.keys())
    first_x = axis[0]
    top = data[first_x][1]
    bottom = data[first_x][0]
    top_dist = bottom_dist = 0

    for x in axis:
        curr_top = data[x][1]
        curr_bottom = data[x][0]
        size = curr_top - curr_bottom
        curr_top_dist = size + min(top_dist + abs(curr_bottom - top), bottom_dist + abs(curr_bottom - bottom))
        curr_bottom_dist = size + min(top_dist + abs(curr_top - top), bottom_dist + abs(curr_top - bottom))
        top = curr_top
        bottom = curr_bottom
        top_dist = curr_top_dist
        bottom_dist = curr_bottom_dist

    distance = axis[-1] - axis[0] + min(top_dist, bottom_dist)
    print(distance)
