import java.util.*;

public class Volcanoes {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        ArrayList<Integer[]> arr = new ArrayList<>();
        HashMap<Integer, Integer[]> map = new HashMap<>();

        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            if (map.containsKey(x)) {
                Integer[] val = map.get(x);
                map.put(x, new Integer[]{Math.min(val[0], y), Math.max(val[1], y)});
            } else {
                map.put(x, new Integer[]{y, y});
            }
        }

        ArrayList<Integer> keys = new ArrayList(map.keySet());

        keys.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1, o2);
            }
        });

        int dxs = Math.abs(keys.get(keys.size() - 1) - keys.get(0));
        int dys = 0;

        int zmin = 0;
        int zmax = 0;

        for (int i = 0; i < keys.size() - 1; i++) {
            Integer[] curr = map.get(keys.get(i));
            Integer[] next = map.get(keys.get(i+1));
            if (i % 2 == 0) {
                zmin += Math.abs(next[1] - curr[0]);
                zmax += Math.abs(next[0] - curr[1]);
            } else {
                zmin += Math.abs(next[0] - curr[1]);
                zmax += Math.abs(next[1] - curr[0]);
            }
            dys += curr[1] - curr[0];
        }

        int res_min = dxs + dys + zmin;
        int res_max = dxs + dys + zmax;
        System.out.println(Math.min(res_min, res_max));
    }
}
