#include <iostream>
#include <bits/stdc++.h>

using namespace std;
vector <int> a;
int main()
{
    int n, x, res;
    cin >> n >> x;
    for (int i=0;i<n;i++)
    {
        int c;
        cin >> c;
        a.push_back(c);
    }
    sort (a.begin(),a.end());
    if (x>=a[0] && x <=a[n-1]){
    if ((x-a[0])>(a[n-1]-x)) res=2*(a[n-1]-x)+x-a[0];
    else res=2*(x-a[0])+a[n-1]-x;}
    else if (x<a[0]) res=a[n-1]-x;
    else res=x-a[0];
    cout << res;

    return 0;
}