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

void main() {
    const tmp = readln.split.to!(long[]);
    const N = tmp[0], K = tmp[1];
    const as = readln.split.to!(long[]);

    ulong X = 0;
    foreach_reverse(i; 0..64) {
        const cnt = as
            .map!(a => a >> i)
            .map!(a => a & 1)
            .sum;

        if (cnt * 2 >= N) continue;
        const po = (1L << i);
        if ((X | po) > K) continue;
        X |= po;
    }
    writeln(as.map!(a => a^X).sum);
}

