unittest
{
	assert( [ "3 7", "1 6 3" ].parse.expand.solve == 14 );
	assert( [ "4 9", "7 4 0 3" ].parse.expand.solve == 46 );
	assert( [ "1 0", "1000000000000" ].parse.expand.solve == 1000000000000 );
	
	assert( [ "3 6", "1 2 4" ].parse.expand.solve == 13 );		// 追加ケース
	assert( [ "3 5", "1 2 4" ].parse.expand.solve == 12 );		// 追加ケース
}
 
 
 
import core.bitop;
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;
 
void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}
 
auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( nk[ 1 ], as );
}
 
auto solve( long k, long[] as )
{
	// Aをbitごとに合計
	auto kbn = ( k == 0 ) ? 1 : k.bsr + 1;
	auto bns = new long[ kbn ];
	foreach( a; as )
	{
		auto abn = ( a == 0 ) ? 1 : a.bsr + 1;
		for( auto i = 0L, b = 1L; i < kbn && i < abn; i++, b <<= 1 )
		{
			bns[ i ] += ( ( a & b ) != 0 );
		}
	}
	
	// bitごとの合計がNの半分より少ない桁はXのbitを立てる（XがKを超える場合を除く）
	auto x = 0L;
	auto unk = false;
	for( auto i = kbn - 1, b = 1L << ( kbn - 1 ); 0 <= i; i--, b >>= 1 )
	{
		auto xb = ( bns[ i ] * 2 < as.length );
		if( !unk )
		{
			auto kb = ( ( k & b ) != 0 );
			xb = ( xb && xb <= kb );
			unk = ( xb < kb );
		}
		if( xb ) x |= b;
	}
	
	// XORの足し算を計算
	return reduce!( ( t, a ) => t + ( x ^ a ) )( 0L, as );
}
