import std.algorithm;
import std.range;
import std.stdio;
import std.math;
import std.array;
import std.string;
import std.conv;
import std.typecons;

/// 数列の読み込み
auto readNums(T = int)() {
	return readln().chomp.split.map!(to!T).array;
}

/// 数の読み込み
auto readNum(T = int)() {
	return readNums!T.front;
}

/// 指定行数読み込み
auto readRows(size_t rows) {
	return generate(() => readln().chomp).take(rows).array;
}

/// 範囲の計算
auto range(T)(T a, T b, T c, T d) {
    auto start = max(a, c);
    auto end = max(b, d);
    return (start < end) ? tuple(start, end) : tuple(cast(T) 0, cast(T) 0);
}

auto maxElement(R)(R r) {
    return r.reduce!((a, b) => max(a, b));
}

auto minElement(R)(R r) {
    return r.reduce!((a, b) => min(a, b));
}

void main() {
	auto k = readNums()[1];
	auto masks = readNums!ulong();
	size_t[size_t] bitCount;
	foreach(m; masks) {
		for(size_t i = 0; m; m >>>= 1, ++i) {
			auto p = i in bitCount;
			if(m & 1) {
				bitCount[i] = p ? *p + 1 : 1;
			} else if(!p) {
				bitCount[i] = 0;
			}
		}
	}
	
	auto t = (masks.length + 1) / 2;
	auto xBits = bitCount.byPair.filter!((a) => a[1] < t);
	auto x = reduce!((a, b) => a | 1UL << b[0])(0UL, xBits);
	for(size_t i = 0; k < x; ++i) {
		x &= ~(1UL << i);
	}
	
	for(auto fillBit = 1UL << (bitCount.byKey.maxElement + 1);
			x + fillBit <= k; x += fillBit, fillBit <<= 1) {
		// do nothing.
	}
	writefln("%d", masks.map!((a) => a ^ x).sum);
}
