#include <iostream>
#include <algorithm>
using namespace std;

// Position
class Position {
public:
	Position();
	Position(int x, int y);
	Position(const Position& other);
	int GetX() const;
	int GetY() const;
	static int GetDistanceX(Position A, Position B);
private:
	int _x;
	int _y;
};

Position::Position() {
	;
}

Position::Position(int x, int y) :
	_x(x), _y(y)
{
	// intのコンストラクタを呼び出す．
}

// コピーコンストラクタ
Position::Position(const Position& other) {
	_x = other.GetX();
	_y = other.GetY();
}

int Position::GetX() const {
	return _x;
}

int Position::GetY() const {
	return _y;
}

int Position::GetDistanceX(Position A, Position B) {
	return abs(A._x - B._x);
}


// Ball
class Ball {
public:
	int GetID() const;
	void SetID(int id);
	Position GetPosition() const;
	void SetPosition(Position& pos);

	Ball();
	Ball(const Ball& other);
	Ball(int id, const Position& pos);
	Ball(int id, int x, int y);
private:
	int _id;
	Position* _position;
};

Ball::Ball() {

}

Ball::Ball(int id, const Position& pos) :
	_id(id)
{
	_position = new Position(pos);
}

Ball::Ball(int id, int x, int y) :
	Ball(id, Position(x, y)) {

}

int Ball::GetID() const {
	return _id;
}

void Ball::SetID(int id) {
	_id = id;
}

Position Ball::GetPosition() const {
	return *_position;
}

void Ball::SetPosition(Position& pos) {
	_position = &pos;
}



// BallManager
class BallManager {
public:
	void SetBall(int i, Ball const* ball);
	void GetBall(int i, Ball** pp_ball) const;
	BallManager(int size, int* const x);
private:
	int _size;
	Ball* _balls;
};

void BallManager::GetBall(int i, Ball** pp_ball) const {
	*pp_ball = &_balls[i - 1];
}

void BallManager::SetBall(int i, Ball const* ball) {
	_balls[i] = *ball;
}

BallManager::BallManager(int size, int* const x) {
	_size = size;
	_balls = new Ball[_size];
	for (int i = 0; i < _size; i++) {
		_balls[i].SetID(i + 1);
		_balls[i].SetPosition(*(new Position(x[i], i + 1)));
	}
}


// Robot
class Robot {
public:
	int GetID() const;
	virtual int GetDistance(BallManager* const bm) const = 0;
	void SetID(int id);
	virtual void SetPosition(int y) = 0;
protected:
	int _id;
	Position* _position = NULL;
};

void Robot::SetID(int id) {
	_id = id;
}

int Robot::GetID() const {
	return _id;
}


// TypeA
class TypeA :public Robot {
public:
	static const int X = 0;
	int GetDistance(BallManager* const bm) const;
	void SetPosition(int y);
};

int TypeA::GetDistance(BallManager* const bm) const {
	Ball* pb = NULL;
	bm->GetBall(_id, &pb);
	return Position::GetDistanceX(*_position, pb->GetPosition());
}

void TypeA::SetPosition(int y) {
	_position = new Position(0, y);
}


// TypeB
class TypeB :public Robot {
public:
	static int X;
	int GetDistance(BallManager* const bm) const;
	void SetPosition(int y);
};

int TypeB::X;

int TypeB::GetDistance(BallManager* const bm) const {
	Ball* pb = NULL;
	bm->GetBall(_id, &pb);
	return Position::GetDistanceX(*_position, pb->GetPosition());
}

void TypeB::SetPosition(int y) {
	_position = new Position(X, y);
}


// Main
int main() {
	int N = 0;
	int K = 0;
	cin >> N >> K;
	TypeB::X = K;
	int* x = new int[N];
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}

	BallManager bm(N, x);

	Robot* a_typeA = new TypeA[N];
	for (int i = 0; i < N; i++) {
		a_typeA[i].SetID(i + 1);
		a_typeA[i].SetPosition(i+1);
	}
	Robot* a_typeB = new TypeB[N];
	for (int i = 0; i < N; i++) {
		a_typeB[i].SetID(i + 1);
		a_typeB[i].SetPosition(i + 1);
	}
	

	int Ans = 0;
	for (int i = 0; i < N; i++) {
		Ans += min<int>(a_typeA[i].GetDistance(&bm), a_typeB[i].GetDistance(&bm));
	}
	Ans *= 2;
	cout << Ans << endl;
}


Measured memory_bytes: 256