#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void solve(int cs) {
int n;
int64_t k;
cin >> n >> k;
vector<int64_t> a(n);
for (int64_t &i : a) cin >> i;
vector<vector<int64_t>> dp(41, vector<int64_t>(2,0));
for (int i = 0; i < 41; i++) {
for (auto it : a) {
if (it >> i & 1) {
dp[i][0] += 1 << i;
} else {
dp[i][1] += 1 << i;
}
}
}
int64_t res = 0, sum = 0;
for (int i = 40; ~i; --i) {
if (k >> i & 1) {
int64_t now = sum + dp[i][0];
for (int j = i - 1; ~j; j--) {
now += max(dp[j][0], dp[j][1]);
}
res = max(res, now);
sum += dp[i][1];
} else {
sum += dp[i][0];
}
}
cout << max(sum, res) << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc = 1;
// cin >> tc;
for (int cs = 1; cs <= tc; cs++) {
solve(cs);
}
return 0;
}