#include <bits/stdc++.h>
#ifdef LOCAL
#include "../algo/debug.h"
#else
#define debug(...) 0
#endif
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
long long k;
cin >> n >> k;
vector<long long> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long ans = 0, w = 0;
for (int b = 40; b >= 0; b--) {
long long now[2] {};
for (int i = 0; i < n; i++) {
if (a[i] >> b & 1) {
now[0] += 1ll << b;
} else {
now[1] += 1ll << b;
}
}
if (w + (1ll << b) <= k) {
if (now[1] > now[0]) {
w += 1ll << b;
ans += now[1];
} else {
ans += now[0];
}
} else {
ans += now[0];
}
}
cout << ans << '\n';
return 0;
}