#include <bits/stdc++.h>

using namespace std;
typedef unsigned long long ul;

int main(void)
{
    ios_base::sync_with_stdio(false);
    int n, x, x1;
    ul res;
    int max_, min_;

    scanf("%d %d", &n, &x);
    scanf("%d", &x1);
    max_ = x1;
    min_ = x1;

    for(int i = 1; i < n; ++i){
        scanf("%d", &x1);
        if(x1 > max_) max_ = x1;
        else if(x1 < min_) min_ = x1;
    }
    if(min_ > x)
        res = (ul)max_ - (ul)x;
    else
        if(max_ < x)
            res = (ul)x - (ul)min_;
        else
            if(max_ - x < x - min_)
                res = (ul)max_ - (ul)x + ((ul)max_ - (ul)min_);
            else
                res = (ul)x - (ul)min_ + ((ul)max_ - (ul)min_);

    printf("%llu", res);

}