#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main () {
cin.tie(0)->sync_with_stdio(0);
int n, k, ans = 0, sum = 0;
cin >> n >> k;
int a[n];
int bt[42]{};
int ct[42]{};
for (int i = 0; i < n; i++) {
cin >> a[i];
int pos = 0, cnt = 41;
while (cnt--) {
if (a[i]%2 == 0) {
bt[pos]++;
}
else ct[pos]++;
pos++;
a[i] /= 2;
}
}
for (int i = 0; i < 42; i++) {
bt[i] *= (1LL<<i);
ct[i] *= (1LL<<i);
}
for (int i = 41; i >= 0; i--) {
if ((1LL<<i)&k) {
int tot = 0;
for (int j = 0; j < i; j++) {
tot += max (bt[j], ct[j]);
}
ans = max (ans, tot+sum+ct[i]);
sum += bt[i];
}
else sum += ct[i];
}
ans = max (ans, sum);
cout << ans << "\n";
}