#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];
}
vector now(2, vector<long long> (41));
for (int b = 40; b >= 0; b--) {
for (int i = 0; i < n; i++) {
if (a[i] >> b & 1) {
now[0][b] += 1ll << b;
} else {
now[1][b] += 1ll << b;
}
}
}
long long sum = 0, ans = 0;
for (int i = 40; i >= 0; i--) {
if (k >> i & 1) {
long long p = sum + now[0][i];
for (int j = i - 1; j >= 0; j--) {
p += max(now[0][j], now[1][j]);
}
ans = max(ans, p);
sum += now[1][i];
} else {
sum += now[0][i];
}
}
ans = max(ans, sum);
cout << ans << '\n';
return 0;
}