/*
ID: seekho
PROG: friday
LANG: C++14                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(998244353)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
// const int N = 100005;

vector<pair<ll,int>> ffk(40);
ll k;int n;
map<ll,ll> M[40];
ll go(int i, ll sum) {

    if(i >= 40) {
        return 0;
    }

    if(M[i].find(sum) != M[i].end()) {
        return M[i][sum];
    }



    ll &ans = M[i][sum];
    ll t0 = 0, t1 = 0;
    if(ffk[i].Y == 0) {
        t0 = ffk[i].X * (1ll << i);
        t1 = (n - ffk[i].X) * (1ll << i);
    }
    else {
        t1 = ffk[i].X * (1ll << i);
        t0 = (n - ffk[i].X) * (1ll << i);        
    }

    if(sum + (1ll << i) <= k) {
        ans = go(i + 1, sum + (1ll << i)) + t1;
    }

    ans = max(ans, go(i + 1, sum) + t0);

    return ans;
}

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);
    
    // int n;
    cin >> n >> k;

    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    vector<pii> tk(40,{0,0});
    ll ans = 0;

    rep(i,40) {
        int cnt1;
        cnt1 = 0;

        rep(j,n) {
            if(a[j] & (1ll << i)) cnt1++;
        } 
        if(cnt1 < n - cnt1) tk[i].X = 1;
        tk[i].Y = max(n-cnt1, cnt1);
        ans += tk[i].Y * (1ll << i);
    } 

    ll fans = 0;
    repD(i,39,0) {
        // bit - 1 -> 0
        if(k & (1ll << i)) {
            int eadd = -tk[i].Y * (1ll << i) + (n - tk[i].Y)  * (1ll << i);
            if(tk[i].X) {
                ans = ans - tk[i].Y * (1ll << i) + (n - tk[i].Y) * (1ll << i);
                eadd = -eadd;
            }
            fans = max(ans, fans);
            ans += eadd;
        }

        // bit - 0
        else {
            if(tk[i].X) {
                ans = ans - tk[i].Y * (1ll << i) + (n - tk[i].Y) * (1ll << i);
            }
        }
    }
    fans = max(fans, ans);
    cout << fans << '\n';
}


// #include <bits/stdc++.h>

// using namespace std;

// typedef long long ll;
// typedef vector<int> vi;
// typedef vector<ll> vl;
// typedef pair<int,int> pii;
// typedef pair<ll,ll> pll;

// typedef int _loop_int;
// #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
// #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
// #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

// #define DEBUG(x) cout<<#x<<": "<<x<<endl
// #define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
// #define ALL(a) (a).begin(),(a).end()

// #define CHMIN(a,b) a=min((a),(b))
// #define CHMAX(a,b) a=max((a),(b))

// // mod
// const ll MOD = 1000000007ll;
// #define FIX(a) ((a)%MOD+MOD)%MOD

// // floating
// typedef double Real;
// const Real EPS = 1e-11;
// #define EQ0(x) (abs(x)<EPS)
// #define EQ(a,b) (abs(a-b)<EPS)
// typedef complex<Real> P;

// int n;
// ll k;
// ll a[125252];
// int cnt1[62];

// ll memo[62][2];
// ll dfs(int b, bool less){
//   if(b<0)return 0ll;
//   if(memo[b][less]!=-1)return memo[b][less];
//   ll ans = 0;
//   if(!less){
//     if(k>>b&1){
//       // 0
//       CHMAX(ans, dfs(b-1,true)+(((ll)cnt1[b])<<b));
//       // 1
//       CHMAX(ans, dfs(b-1,false)+(((ll)(n-cnt1[b]))<<b));
//     }else{
//       // 0
//       CHMAX(ans, dfs(b-1,false)+(((ll)cnt1[b])<<b));
//     }
//   }else{
//     // 0
//     CHMAX(ans, dfs(b-1,true)+(((ll)cnt1[b])<<b));
//     // 1
//     CHMAX(ans, dfs(b-1,true)+(((ll)(n-cnt1[b]))<<b));
//   }
//   return memo[b][less] = ans;
// }

// int main(){
//   scanf("%d%lld", &n, &k);
//   REP(i,n)scanf("%lld",a+i);
//   REP(i,n)REP(b,62){
//     cnt1[b] += (a[i]>>b&1);
//   }
//   REP(i,62)REP(j,2)memo[i][j]=-1;
//   ll ans = dfs(60,false);
//   printf("%lld\n",ans);
//   return 0;
// }



Measured memory_bytes: 1024