
def vulcanoes(dct):
    srts = sorted(dct.items(), key=lambda item: (item[0]))

    pos_x = srts[0][0]
    pos_y_mn = srts[0][1][0]
    pos_y_mx = srts[0][1][1]
    dist_mn = pos_y_mx - pos_y_mn
    dist_mx = pos_y_mx - pos_y_mn
    # print(dist_mn, dist_mx)
    for i in range(1, len(srts)):
        x, (mn, mx) = srts[i]
        # _, y = min([(abs(pos_y-mx), mx), (abs(pos_y-mn), mn)], key =lambda item: item[0])

        dist_mn += abs(x - pos_x)
        dist_mx += abs(x - pos_x)
        # print(dist_mn, dist_mx)

        dist_mn += mx - mn
        dist_mx += mx - mn
        # print(dist_mn, dist_mx)

        mnd = dist_mn + abs(mx - pos_y_mn)
        mxd = dist_mx + abs(mx - pos_y_mx)
        if mnd < mxd:
            new_mnd = mnd
        else:
            new_mnd = mxd

        mnd = dist_mn + abs(mn - pos_y_mn)
        mxd = dist_mx + abs(mn - pos_y_mx)
        if mnd < mxd:
            new_mxd = mnd
        else:
            new_mxd = mxd

        '''
        if pos_y_mn >= mx:
            dist_mn += abs(mx - pos_y_mn)
            dist_mx += abs(mx - pos_y_mx)
        elif pos_y_mx <= mn:
            dist_mn += abs(mn - pos_y_mn)
            dist_mx += abs(mn - pos_y_mx)
        else:
            dist_mn += abs(mn - pos_y_mn)
            dist_mx += abs(mx - pos_y_mx)
        # dist_mn, dist_mx = dist_mx, dist_mn
        # print(dist_mn, dist_mx)
        '''

        dist_mn = new_mnd
        dist_mx = new_mxd

        pos_y_mn = mn
        pos_y_mx = mx

        pos_x = x

    return min(dist_mn, dist_mx)


if __name__ == '__main__':
    dct ={}

    for i in range(int(input())):
        x, y = list(map(int, input().split()))
        if x not in dct:
            dct[x] = (y, y)
        else:
            mn, mx = dct[x]
            dct[x] = (min(mn, y), max(mx, y))
    print(vulcanoes(dct))
"""
4
2 3
3 2
1 1
5 5

5
1 2
5 4
3 6
7 8
1 1

8
1 2
1 4
2 1
2 3
3 3
3 5
4 2
4 4
"""