/*
* author :Sadik Hassan(_sad_)
*
*/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
#define nl "\n"
#define pb push_back
#define fi first
#define se second
#define MP make_pair
#define PI (acos(-1.0))
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define urep(i,n) for(int i=n-1;i>=0;i--)
#define urep1(i,n) for(int i=n;i>=1;i--)
#define SZ(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define w(t) int t;cin>>t;while(t--)
#define _SAD() ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/
const int N = (int)2e5+5;
const int MOD =(int)1e9+7;
const ll INF = (ll)1e18+5;
const int M2 = 998244353;
int main()
{
_SAD()
int n,k;
cin>>n>>k;
ll cnt=0;
vii a;
rep(i,n)
{
ll x;
cin>>x;
if(x<k)
{
a.pb(x);
}
}
sort(all(a));
ll i=0,j=SZ(a)-1;
while(i<=j)
{
ll pp=min(k-a[i],k-a[j]);
cnt+=pp;
a[i]+=pp;
if(i!=j)a[j]+=pp;
if(a[j]>=k)j--;
if(a[i]>=k)i++;
}
cout<<cnt<<nl;
return 0;
}
LyoKICogYXV0aG9yIDpTYWRpayBIYXNzYW4oX3NhZF8pCiAqCiovCiNwcmFnbWEgR0NDIG9wdGltaXplKCJPZmFzdCIpCiNwcmFnbWEgR0NDIHRhcmdldCgiYXZ4LGF2eDIsZm1hIikKI3ByYWdtYSBHQ0Mgb3B0aW1pemF0aW9uICgidW5yb2xsLWxvb3BzIikKI2luY2x1ZGUgImJpdHMvc3RkYysrLmgiCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnVzaW5nICAgbGwgPSAgIC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