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

using namespace std;

int main()
{
    long long n, m, lol=0, poc=0, kraj=0;
    cin >> n >> m;
    long long a[n];
    for(int i = 0;i < n;i++)
        cin >> a[i];
    sort(a, a+n);
    poc=a[0];
    kraj=a[n-1];
    if(abs(m- poc) < abs(m - a[n-1])){
        if(poc > m)
            lol=lol + poc - m;
        else
            lol=lol + m - a[0];
        for(int i = 1;i < n;i++){
                if(a[i] == a[i-1])
                lol=lol + 0;
            lol=lol + a[i] - a[i-1];}
                cout << lol;}
    else{
        if(kraj > m)
            lol = kraj - m;
        else
            lol= m - a[n-1];
        for(int i = 1;i < n;i++){
            if(a[i] == a[i-1])
                lol=lol + 0;
                    lol=lol + a[i] - a[i-1];}
                        cout << lol;}
    return 0;}