#include <bits/stdc++.h>

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

i64 n,k, tmp;
vl a;
/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    cin >> n >> k;
    a.resize(n);
    rep(i,n) cin >> a[i];

    /**
     * 上の桁から決めていって、kより小さいことが確定した場合1,0のどっちでもよし、
     * それまではkに沿って決めなければいけないanswer <= kである必要があるので、それに沿って。
     */

    i64 max_digit = 0LL;
    tmp = 1LL;
    while(tmp < k) {
        tmp<<=1LL;
        ++max_digit;
    }
//    debug(max_digit);
    for(auto num : a) {
        tmp = 1LL;
        i64 tmp_digit = 0;
        while(tmp < num) {
            tmp<<=1LL;
            ++tmp_digit;
        }
        chmax(max_digit, tmp_digit);
    }
//    cout << max_digit << '\n';  // debug

    i64 answer = 0LL;
    bool absolutelySmallerThanK = 0;  // should init with 0
    for(i64 digit = max_digit-1; digit >= 0; --digit) {
        if(absolutelySmallerThanK) {
            i32 cnt1 = 0, cnt0 = 0;
            for(auto p : a) {
                if((p>>digit)&1LL) ++cnt1;
                else ++cnt0;
            }
            answer += (1LL<<digit) * max(cnt1, cnt0);
        }
        else {
            i32 cnt1 = 0, cnt0 = 0;
            for(auto p : a) {
                if((p>>digit)&1LL) ++cnt1;
                else ++cnt0;
            }
            i64 k_bit = (k>>digit)&1;
            i64 bit_use;
            if(cnt1 < cnt0) bit_use = 1LL;
            else if(cnt1 == cnt0) bit_use = k_bit;
            else if(cnt1 > cnt0) bit_use = 0LL;
            if(bit_use > k_bit) bit_use = k_bit;

            if(bit_use < k_bit) absolutelySmallerThanK = 1;
//            debug(bit_use);
            answer += (1LL<<digit) * (bit_use == 0LL ? cnt1 : cnt0);
        }
//        debug(answer);
    }

    cout << answer << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 1024