#include <iostream>
using namespace std;

int main()
{
    long dim, n;
    cin>>n>>dim;
    long bruh, minin=dim, maxin=dim;
    for(int i=0; i<n; i++)
    {
        cin>>bruh;
        if(bruh>maxin) maxin=bruh;
        else if(bruh<minin) minin=bruh;
    }
    cout<<(1+(dim-minin<maxin-dim))*(dim-minin)+(1+(dim-minin>maxin-dim))*(maxin-dim);
    return 0;
}