#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/multiprecision/cpp_int.hpp>

/***** type *****/
using namespace std;
using ll = long long;
using ld = long double;
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
template <class T> using vvvt = vector<vector<vector<T>>>;
using ml = boost::multiprecision::cpp_int;

/***** define *****/
#define all(c) (c).begin(), (c).end()            // begin to end
#define idx(it) it
#define rep(i, b, e) for (ll i = b; i < e; i++)  // repeat
#define repr(i, b, e) for (ll i = b; e < i; i--) // repeat reverse
#define val(it) *(it)								 // get value
/***** const value *****/
#define llong_max 9223372036854775807            // 9 * 10^18
#define ldbl_max 1.79769e+308                    // 1.7 * 10^308
#define mod 1000000007                           // 1e9 + 7
#define pi 3.14159265                            // 3.14 ...
/***** for each macro *****/
#define fori(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#define each(i, e, c) fori(i, auto e = c.begin(); e != c.end(); ++e)
#define forir(i, v, ...) if(ll i = Size(v)) for(__VA_ARGS__) if(i--, true)
#define eachr(i, e, c) forir(i, auto e = c.rbegin(); e != c.rend(); ++e)

/***** lambda *****/
auto Count = [] // long long count value
(auto b, auto e, auto x) { return (ll)count(b, e, x); };
auto CtoN = [] // char to number
(auto c) { return (ll)(c - '0'); };
auto DivC = [] // long double div ceiling
(auto a, auto b) { return ceil((ld)a / (ld)b); };
auto Fix = [] // fix value
(auto b, auto e, auto fix)
{ for (auto it = b; it != e; ++it)* it += fix; }; 
auto NyaN = [] // long long nyan size
(auto n) { return Pow(10, n); };
auto Pow = [] // long long pow
(auto a, auto b) { return (ll)pow(a, b); };
auto Pow2 = [] // long long pow2
(auto n) { return (1LL << n); };
auto Size = []  // long long collection size
(auto& c) { return (ll)(c).size(); };
auto Sum = [] // long long accumulate
(auto b, auto e) { return accumulate(b, e, 0LL); };

/***** template *****/
template <class T> vvt<T> VVT
(ll ys, ll xs, T fill = T())
{	// vector<vector<T>> resize + fill
	vvt<T> v(ys);
	each(i, y, v) { val(y).resize(xs, fill); } return v;
}
template <class T> vvvt<T> VVVT
(ll zs, ll ys, ll xs, T fill = T())
{	// vector<vector<vector<T>>> resize + fill
	vvvt<T> v(zs);
	each(i, z, v) { val(z) = VVT(ys, xs, fill); } return v;
}
template <class T> vt<T> InputVT
(ll size, T fix = T())
{   // input vector<T> (T != struct) + fix
	vt<T> v(size);
	each(i, e, v) { cin >> val(e); val(e) += fix; } return v;
}
template <class T> vvt<T> InputVVT
(ll ys, ll xs, T fix = T())
{   // input vector<vector<T>> (T != struct) + fix
	vvt<T> v(ys); each(i, y, v) val(y).resize(xs);
	each(i, y, v) each(j, x, val(y)) { cin >> val(x); val(x) += fix; } return v;
}
template <class T> vvvt<T> InputVVVT
(ll zs, ll ys, ll xs, T fix = T())
{	// input vector<vector<vector<T>>> (T != struct) + fix
	vvvt<T> v(zs);
	each(i, z, v) { val(z) = InputVVT<T>(ys, xs, fix); } return v;
}

namespace NyaGadget
{
	/*** Bit操作ライブラリ ***/

	struct Bit
	{
		template <class T> static ll Count(T b, T e, ll i, ll sum = 0)
		{
			for (auto it = b; it != e; ++it) sum += Test(*it, i);
			return sum;
		}

		template <class T> static ll Count(T b, T e, ll i, bool flip, ll sum = 0)
		{
			for (auto it = b; it != e; ++it) sum += Test(*it, i, flip);
			return sum;
		}

		static ll Count(ll x, ll i)
		{
			return Test(x, i);
		}

		static ll Count(ll x, ll i, bool flip)
		{
			return Test(x, i, flip);
		}

		static ll To10(ll x, ll i)
		{
			return Test(x, i) * Pow2(i);
		}

		static ll Shift(ll x, ll n)
		{
			return (x << n);
		}

		static ll Size(ll x, ll size = 0)
		{
			while (Pow2(size) <= x) size++;
			return size;
		}

		static ll Test(ll x, ll i)
		{
			return ((x & Shift(1, i)) != 0) ? 1 : 0;
		}

		static ll Test(ll x, ll i, bool flip)
		{
			return (flip) ? x & Shift(1, i) : 1 - (x & Shift(1, i));
		}
	};
}

using namespace NyaGadget;

int main(void)
{
	ll N, K; cin >> N >> K;
	vt<ll> A = InputVT<ll>(N);

	if (K == 0)
	{
		cout << Sum(all(A));
		return 0;
	}

	const ll bitSizeK = Bit::Size(K);
	vt<ll> bitSum(bitSizeK);
	rep(i, 0, bitSizeK) bitSum[i] = Bit::Count(all(A), i);

	vt<ll> greed(bitSizeK);
	greed[0] = (bitSum[0] < N - bitSum[0]) ? Pow2(0) : 0;
	each(i, g, greed)
	{	// 貪欲計算
		if (i == 0) continue;

		if (bitSum[i] < N - bitSum[i]) val(g) = Pow2(i) + val(g - 1);
		else val(g) = val(g - 1);
	}

	ll ans = 0;
	// f(x), x == K
	each(i, a, A) ans += (val(a) ^ K);
	// f(x), x != K
	rep(m, 0, bitSizeK)
	{
		ll test = 0;

		ll x = (0 <= m - 1) ? greed[m - 1] : 0;
		if (Bit::Test(K, m) != 1) continue;
		rep(i, m + 1, bitSizeK) x += Bit::To10(K, i);
		
		each(i, a, A) test += (val(a) ^ x);
		ans = max(ans, test);
	}

	cout << ans;
	return 0;
}


Measured memory_bytes: 1024