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 );
}



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 )
{
	// 2進数表記でKの桁数を計算
	auto kbd = 0L;
	while( 0 < k )
	{
		k /= 2;
		kbd++;
	}
	
	// 2進数表記で各桁ごとの合計数を計算
	auto cs = new long[ kbd ];
	foreach( a; as )
	{
		for( auto i = 0L; 0 < a && i < cs.length; i++ )
		{
			auto d = 2L ^^ ( i + 1 );
			if( a % d != 0 ) cs[ i ]++;
			a -= a % d;
		}
	}
	
	// 合計数がNの半分より少ない桁を足し算
	auto cc = 0L;
	foreach( i, c; cs )
	{
		if( c * 2 <= as.length ) cc += 2L ^^ i;
	}
	
	// XORの足し算を計算
	return as.map!( ( a ) => cc ^ a ).sum;
}
