//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;


//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// type alias
using ll = long long;
using ull = unsigned long long;

// constant value
const ll MOD = 1000000007LL;

// Computational Complexity: O(log(max(a, b))) 
template<class ll>
inline ll getGCD(ll a, ll b)
{
	if (b == 0)
	{
		return a;
	}
	return getGCD(b, a % b);
}

// Computational Complexity: O(log(max(a, b))) 
template<class ll>
inline pair<ll, ll> getBezoutsIdentitySoulution(ll a, ll b)
{
	if (b == 0)
	{
		return { 1, 0 };
	}
	auto sol = getBezoutsIdentitySoulution(b, a % b);
	return { sol.second, sol.first - (a / b) * sol.second };
}

inline ll getModValue(ll a, ll m)
{
	return (a % m + m) % m;
}

// Computational Complexity: O(log(max(a, n))) 
inline ll getModInverse(ll a, ll m)
{
	auto sol = getBezoutsIdentitySoulution(a, m);
	if (a * sol.first + m * sol.second != 1)
	{
		return -1;
	}
	return getModValue(sol.first, m);
}

ll getModCombinatorialNumber(ll n, ll r, ll m)
{
	ll res = 1;
	for (; n > 0; --n, --r)
	{
		res = (((res * n) % m) * getModInverse(n, m)) % m;
	}
	return getModValue(res, m);
}

map<ll, ull> getPrimeFactorization(ll num)
{
	map<ll, ull> primeToCount;

	int rootNum = sqrt(num);
	vector<bool> isCompositeNumber(rootNum + 1, false);
	for (int p = 2; num != 1 && p <= rootNum; ++p)
	{
		if (!isCompositeNumber[p])
		{
			for (int i = p * 2; i <= rootNum; i += p)
			{
				isCompositeNumber[i] = true;
			}

			int count = 0;
			while (num % p == 0)
			{
				++count;
				num /= p;
			}
			if (count >= 1)
			{
				primeToCount.insert(make_pair(p, count));
			}
		}
	}
	if (num != 1)
	{
		primeToCount.insert(make_pair(num, 1));
	}

	return primeToCount;
}

template<class ll>
inline ll getCeilExponent(ll a)
{
    if (a <= 0)
    {
        return 0;
    }

    ll index = 0;
    --a;
    for( ; a != 0; a >>= 1 )
    {
        ++index;
    }
    return index;
}

template<class ll>
inline ll getFloorExponent(ll a)
{
    if (a <= 0)
    {
        return 0;
    }

    ll index = 0;
    a >>= 1;
    for( ; a != 0; a >>= 1 )
    {
        ++index;
    }
    return index;
}

class UnionFindTree
{
private:
    const unsigned elemCount_;
    vector<unsigned> parentNodeNumbers_;
    vector<unsigned> treeDepths_;
    
	// Average Computational Complexity: O(log(elemCount_))) 
	unsigned getRootNode(unsigned x)
    {
        if (parentNodeNumbers_[x] == x)
        {
            return x;
        }
        else
        {
            return getRootNode(parentNodeNumbers_[x]);
        }
    }

public:
    UnionFindTree(unsigned elemCount) : elemCount_(elemCount), parentNodeNumbers_(elemCount), treeDepths_(elemCount, 0)
    {
        for (unsigned i = 0; i < parentNodeNumbers_.size(); ++i) 
        {
            parentNodeNumbers_[i] = i;
        }
    }

	// Average Computational Complexity: O(log(elemCount_))) 
	void uniteSet(unsigned x, unsigned y)
    {
        x = getRootNode(x);
        y = getRootNode(y);
        if ( x == y )
        {
            return;
        }
        
        if (treeDepths_[x] < treeDepths_[y])
        {
            parentNodeNumbers_[x] = y;
        }
        else
        {
            parentNodeNumbers_[y] = x;
            if (treeDepths_[x] == treeDepths_[y])
            {
                ++treeDepths_[x];
            }
        }
    }

	// Average Computational Complexity: O(log(elemCount_))) 
	bool includedInSameSet(unsigned x, unsigned y)
    {
        return getRootNode(x) == getRootNode(y);
    }
};



ll calcXorForOneBit(const vector<ll>& as, unsigned pos, bool isOne)
{
	ll n = as.size();

	ll res = 0;
	ll tmp;
	for (int i = 0; i < n; ++i)
	{
		tmp = ((as[i] >> pos) & 1);
		if (isOne) {
			tmp ^= 1;
		}
		tmp <<= pos;
		res += tmp;
	}

	return res;
}

ll calcMaxXorForPowerTwo(const vector<ll>& as, unsigned exponent)
{
	ll res = 0;
	for (int i = 0; i < 40; ++i)
	{
		if (i < exponent)
		{
			res += max(calcXorForOneBit(as, i, true), calcXorForOneBit(as, i, false));
		}
		else
		{
			res += calcXorForOneBit(as, i, false);
		}
	}
	return res;
}

ll calcMaxXor(const vector<ll>& as, ll k, const vector<ll> &vecMaxXorForPowerTwo)
{
	if (k == 0)
	{
		return vecMaxXorForPowerTwo[0];
	}

	auto e = getFloorExponent(k);
	
	return max(
		vecMaxXorForPowerTwo[e],
		calcMaxXor(as, k - (1LL << e), vecMaxXorForPowerTwo)
		+ calcXorForOneBit(as, e, true) - calcXorForOneBit(as, e, false)
	);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n, k;
	cin >> n >> k;
	
	vector<ll> as(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> as[i];
	}

	vector<ll> vecMaxXorForPowerTwo(40);
	for (int i = 0; i < 40; ++i)
	{
		vecMaxXorForPowerTwo[i] = calcMaxXorForPowerTwo(as, i);
	}

	cout << calcMaxXor(as, k, vecMaxXorForPowerTwo);

	return 0;


}




Measured memory_bytes: 1024