/*
 http://drken1215.hatenablog.com/entry/2019/02/04/013700
 */

#include<bits/stdc++.h>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//manip
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power_mod(T a, T b) {return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i, n) cout << a[i] << " "; cout << endl
#define outaa(a, m, n) rep(i, m) {rep(j, n) cout << a[i][j] << " "; cout << endl;} cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl

//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always



//power関数でmodとってた
//それに気づかんかった

ll f(int n, ll k, ll a[]) {
    ll dp[41][4]; fill_n(*dp, 41 * 4, -1);
    dp[0][0] = 0;
    //outaa(dp, 41, 2);
    
   
    rep(i, 40) {
        int look_bit = 39 - i;
        ll power_of_two = power((ll)2, (ll)look_bit);
        //cout << power_of_two << endl;
        int a_bit_1 = 0;
        rep(j, n) if (a[j] & power_of_two) a_bit_1++;
        //cout << a_bit_1 << endl;
        
        ll cost_x_bit_0 = a_bit_1 * power_of_two;
        ll cost_x_bit_1 = (n - a_bit_1) * power_of_two;
        //cout << cost_x_bit_0 << " " << cost_x_bit_1 << endl;
        
        if (dp[i][1] != -1) { //from smaller (only to smaller)
            chmax(dp[i + 1][1], dp[i][1] + max(cost_x_bit_0, cost_x_bit_1));
            
        }
        
        if (dp[i][0] != -1) { //from exact to smaller
            if (k & power_of_two) { //smallerにするということはkに1、今見る数は0にする
                chmax(dp[i + 1][1], dp[i][0] + cost_x_bit_0);
            }
        }
        
        //from exact to exact
        if (dp[i][0] != -1) {
            //(0, 0) or (1, 1)
            if (k & power_of_two) { //(1, 1)
                chmax(dp[i + 1][0], dp[i][0] + cost_x_bit_1);
            } else {
                chmax(dp[i + 1][0], dp[i][0] + cost_x_bit_0);
            }
            
        }
        
        
    }
    
    //rep(i, 41) {rep(j, 2) cout << dp[i][j] << " "; cout << endl;}
    
    return max(dp[40][0], dp[40][1]);
}

int main() {
    
    int n; ll k; cin >> n >> k;
    ll a[n]; rep(i, n) cin >> a[i];
    
    out(f(n, k, a));
    
    
}



Measured memory_bytes: 1024