#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;
int l = __lg(k);
vector<int> cnt(l + 1, 0);
for (int i = 0; i <= l; i++) {
for (auto it : a) {
if (it >> i & 1) cnt[i] -= 1;
else cnt[i] += 1;
}
}
int64_t p = 0;
bool done = false;
for (int i = 0; i <= l; i++) {
if (cnt[i] > 0) {
if (k >> i & 1) {
p |= (1 << i);
} else if (done) {
p |= (1 << i);
}
} else if (p >> i & 1) {
done = 1;
}
}
int64_t ans = 0;
for (auto it : a) ans += it ^ p;
cout << ans << "\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;
}