#include <bits/stdc++.h>

using namespace std;

int n, x;
int a[1000005];
int maxi=-100000001,mini=100000001;
int put;

int main()
{
    scanf("%d %d",&n, &x);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(int i=0;i<n;i++)
        maxi=max(maxi,a[i]),mini=min(mini,a[i]);
    if(maxi<x)
    {
        put=abs(x-mini);
        printf("%d",put);
        return 0;
    }
    if(mini>x)
    {
        put=abs(maxi-x);
        printf("%d",put);
        return 0;
    }
    put=2*min(abs(maxi-x),abs(x-mini))+max(abs(maxi-x),abs(x-mini));
    printf("%d",put);
    return 0;
}