#include <iostream>
#include <stdio.h>
#include <cmath>

using namespace std;

int main(){
    int n;
    long long a,x,min,max,z;
    cin >> n >> x;
    for(int i=0;i<n;i++)
    {
        cin >> a;
        if(i==0) {min=a;max=a;}
        else
        {
            if(min>a) min=a;
            if(max<a) max=a;
        }
    }
    if(x<=min) z=abs(max-x);
    if(min<x<max)
    {
        if(abs(x-min)>abs(max-x)) z=abs(max-x)+abs(max-min);
        if(abs(x-min)<=abs(max-x)) z=abs(x-min)+abs(max-min);
    }
    if(x>=max) z=abs(x-min);
    cout << z;

    return 0;
}