#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define endl '\n'
const int N = 1e6+4;
void solve(int cs){
int n;cin>>n;
ll k;cin>>k;
std::vector<ll>v ;
int bit[50] = {0};
for(int i = 0; i < n; i++){
ll a;cin>>a;
v.push_back(a);
for(int j = 0; j < 46; j++){
if((a&(1ll<<j)))bit[j]++;
}
}
//cout<<(3&4) <<" "<<(1&4) <<" "<<(6&4)<<endl;
//cout<<bit[2]<<endl;
ll ans = 0;
ll tm = 0;
for(int i = 45; i>=0; i--){
int unset = n-bit[i];
if(bit[i] < unset){
if((tm|(1ll<<i)) <= k){
tm |= (1ll<<i);
}
}
}
if(tm == 0)tm = 1;
for(auto u:v){
ans += (u^tm);
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);
int t=1,cs=0;
//cin >> t;
while(t--)
{
solve(++cs);
}
return 0;
}