#include <iostream>
#include <vector>
using namespace std;
long long m(vector<long long>& a, long long k) {
long long m_f = 0;
long long mask = 1LL << 60;
while (mask > 0) {
long long c_1 = 0;
for (long long a_val : a) {
if (a_val & mask)
c_1++;
}
if ((k & mask) && c_1 <= a.size() - c_1) {
m_f |= mask;
}
mask >>= 1;
}
long long result = 0;
for (long long a_val : a) {
result += a_val ^ m_f;
}
return result;
}
int main() {
int n;
long long k;
cin >> n >> k;
vector<long long> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
cout << m(a, k) << endl;
return 0;
}