#include <bits/stdc++.h>
typedef long long ll;
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define CheckBit(x,k) (x & (1LL << k))
#define SetBit(x,k) (x |= (1LL << k))
#define ClearBit(x,k) (x &= ~(1LL << k))
#define MSB(mask) 63-__builtin_clzll(mask)
#define LSB(mask) __builtin_ctzll(mask)
#define error1(x) cerr << #x << " = " << (x) <<endl
#define error2(a,b) cerr<<"("<<#a<<", "<<#b<<") = ("<<(a)<<", "<<(b)<<")\n";
#define coutall(v) for(auto &it: v) cout<<it<<" "; cout<<endl;
#define _ASRafi__ ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
void solve()
{
ll n, k, ans = 0;
cin >> n >> k;
vector<bitset<41>> v(n);
for (int i = 0; i < n; i++) {
ll x; cin >> x;
v[i] = x;
}
vector<pair<ll, ll>> profit(41);
for(int i = 0; i < 41; i++) {
ll c1 = 0;
for(int j = 0; j < n; j++) c1 += v[j][i];
// if x[i] = 1
ll lab = (n - c1) * (1LL << i), loss = c1 * (1LL << i);
profit[i] = {lab, loss};
// cout << i << " -> " << lab << ", " << loss << endl;
}
bitset<41> b1 = k;
bool ok = 0;
for(int i = 40; i >= 0; i--) { // sob nibo
if(ok) ans += max(profit[i].F, profit[i].S);
else if(profit[i].F <= profit[i].S){
ans += max(profit[i].F, profit[i].S);
if(b1[i] == 1) ok = 1;
}
else if(b1[i] == 1) ans += profit[i].F;
else ans += profit[i].S;
// cout << i << " => " << ans << endl;
}
ll back = 0;
for(int i = 40; i >= 0; i--) { // nibo na
if(b1[i] == 1) {
ll tmp = back;
for(int j = i - 1; j >= 0; j--) {
tmp += max(profit[j].F, profit[j].S);
}
ans = max(ans, tmp);
}
if(b1[i] == 1) back += max(profit[i].F, profit[i].S);
else back += profit[i].S;
}
cout << ans << endl;
return;
}
int32_t main()
{
_ASRafi__;
int tc = 1;
// cin >> tc;
for (int t = 1; t <= tc; t++)
{
// cout << "Case " << t << ": ";
solve();
}
return 0;
}