#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
// #define cerr cout
#include "algo/debug.h"
#else
#define deb(...) 30
#endif
#define ll long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k;
    cin >> n >> k;
    ll x = 0, ans = 0, lst = 0;
    f(i, k) if (k >> i & 1) lst = i;
    vector<int> v(n);
    int cnt[31];
    f(i, n) cin >> v[i];
    f(i, n) {
        f(j, 30) {
            if (v[i] >> j & 1)
                cnt[j]++;
        }
    }
    ans = 0;
    for (int k = 0; k <= lst; k++) {
        if (cnt[k] < n - cnt[k]) {
            ans |= (1 << k);
        }
    }
    ll mx = 0, mx2 = 0;
    for (auto a : v)
        mx += (a ^ ans), mx2 += (a ^ k);
    cout << max(mx, mx2) << '\n';
    return 0;
}