import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto N = RD!ulong;
	auto K = RD!ulong;
	auto A = RDR.split.to!(ulong[]);

	ulong[64] bitCnt;
	foreach (e; A)
	{
		foreach (i; 0..64)
		{
			if (e & (cast(ulong)1 << i)) ++bitCnt[i];
		}
	}
	auto bitQ = new ulong[](64);
	fill(bitQ, ulong.max);
	foreach (ulong i; 0..64)
	{
		if (bitCnt[i] > N / 2) continue;
		bitQ[i] = ((N - bitCnt[i]) - bitCnt[i]) * (cast(ulong)1 << i);
	}

	//stderr.writeln(bitQ);
	ulong x;
	ulong ans;
	foreach_reverse (ulong i, e; bitQ)
	{
		if (bitCnt[i] > N / 2) continue;

		
		ulong bit = cast(ulong)1 << i;
		//stderr.writeln(x, " a ", i , " ", bit);
		x += bit;
		if (x > K)
		{
			ulong best = ulong.max, bestPos;
			/*foreach (j, ee; bitQ[i..$])
			{
				if (ee < best)
				{
					best = ee;
					bestPos = i + j;
				}
			}*/
			foreach_reverse (ulong j; i..64)
			{
				if (x & (cast(ulong)1 << j))
				{
					if (bitQ[j] < best)
					{
						best = bitQ[j];
						bestPos = j;
					}
				}
			}
			x -= cast(ulong)1 << bestPos;
			//stderr.writeln(x, " ", i, " ", bestPos);
		}
		else
		{
			//stderr.writeln("else");
		}
	}

	foreach (e; A)
	{
		ans += e ^ x;
	}

	writeln(ans);
	stdout.flush();
}