/* 
 * Solution by Christian Kauth - July 2010 - Solves all testcases at http://ioinformatics.org/locations/ioi04/contest/ioi2004-test-data.zip
 * Each message can be sent from a cross (centered at the god's bar). Compute the minimal distance for each position on the current cross 
 * from the minimal distance on the previous cross by dynamic programming
 */

#include <iostream>
using namespace std;

#define MAX_SIZE 2001
#define INF 400000001
#define OFFSET 1000

int N;
int hor[2][MAX_SIZE], ver[2][MAX_SIZE];
int x[2], y[2];
bool ok;

void initialize()
{
	cin>>N;
	ok=false;
	x[ok] = y[ok] = OFFSET;
	for (int i=0; i<MAX_SIZE; i++)
		hor[ok][i] = ver[ok][i] = abs(i-OFFSET);
}

void make_move()
{
	cin>>x[!ok]>>y[!ok];
	x[!ok] += OFFSET;
	y[!ok] += OFFSET;
	for (int i=0; i<MAX_SIZE; i++)
	{
		hor[!ok][i] = min ( hor[ok][i]+abs(y[ok]-y[!ok]) , ver[ok][y[!ok]]+abs(x[ok]-i) );
		ver[!ok][i] = min ( ver[ok][i]+abs(x[ok]-x[!ok]) , hor[ok][x[!ok]]+abs(y[ok]-i) );
	}
	ok = !ok;
}

void output()
{
	int minSteps(INF);
	for (int i=0; i<MAX_SIZE; i++)
		minSteps = (hor[ok][i] < ver[ok][i]) ? min(hor[ok][i],minSteps) : min(ver[ok][i],minSteps);
	cout<<minSteps<<endl;
}

int main()
{
	initialize();
	for (int i=0; i<N; i++)
		make_move();
	output();
	return 0;
}
