#include <iostream>

using namespace std;

typedef unsigned long long ull;

static ull n, x;

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    	cin >> n >> x;
        	int min = x, max = x;
            	while (n--)
                	{
                    		int broj;
                            		cin >> broj;
                                    		if (broj < min)
                                            			min = broj;
                                                        		else if (broj > max)
                                                                			max = broj;
                                                                            	}
                                                                                	if (min == x)
                                                                                    		cout << max - x;
                                                                                            	else if (max == x)
                                                                                                		cout << x - min;
                                                                                                        	else if (max - x > x - min)
                                                                                                            		cout << 2 * (x - min) + max - x;
                                                                                                                    	else
                                                                                                                        		cout << x - min + 2 * (max - x);
                                                                                                                                }