#include <bits/stdc++.h>
using namespace std;
#define SC scanf
#define PF printf
#define ull unsigned long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sort_a(a) sort(a.begin(),a.end());
#define sort_d(a) sort(a.rbegin(),a.rend());
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define rev(s) reverse(s.begin(),s.end())
#define P(ok) cout << (ok ? "YES\n": "NO\n")
#define __Heart__ ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll> PII;
ll dp[55][2] , n , k;
map < int , int > bit ;
ll Heart(int pos , bool afterBitMatchK) {
if(pos < 0) return 0LL ;
if(dp[pos][afterBitMatchK] != -1) return dp[pos][afterBitMatchK] ;
if(k & (1LL << pos)) {
dp[pos][afterBitMatchK] = max(dp[pos][afterBitMatchK] , Heart(pos - 1 , 1) + (bit[pos]) * (1LL << pos)) ;
dp[pos][afterBitMatchK] = max(dp[pos][afterBitMatchK] , Heart(pos - 1 , afterBitMatchK) + (n - bit[pos]) * (1LL << pos)) ;
}
else {
dp[pos][afterBitMatchK] = max(dp[pos][afterBitMatchK] , Heart(pos - 1 , afterBitMatchK) + (bit[pos]) * (1LL << pos)) ;
if(afterBitMatchK) dp[pos][afterBitMatchK] = max(dp[pos][afterBitMatchK] , Heart(pos - 1 , afterBitMatchK) + ( n - bit[pos]) * (1LL << pos)) ;
}
return dp[pos][afterBitMatchK] ;
}
void solve()
{
cin >> n >> k ; ll a[n] ;
for(int i = 0 ; i < n ; i++)
{
cin >> a[i] ;
for(int j = 0 ; j < 50 ; j++)
{
if((1LL << j) & a[i]) bit[j]++ ;
}
}
for(int i = 0 ; i <= 50 ; i++) dp[i][0] = dp[i][1] = -1 ;
cout << Heart(50 , 0) << "\n" ;
}
int main()
{
__Heart__
//READ("input26.txt") ;
// WRITE("output26.txt");
int t ; t = 1 ; while(t--) solve() ;
}