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[]);

    long value(int i, int b) {
        return as
            .map!(a => a >> i)
            .map!(a => a & 1)
            .map!(a => a ^ b)
            .map!(a => a << i)
            .sum;
    }

    long func(int i, int X) {
        if (K == 0) return as.sum;
        const w = 1 << i;
        if (X > K) return 0;
        if (w > K) return 0;
        return max(memoize!func(i+1, X) + memoize!value(i,0), memoize!func(i+1, X + w) + memoize!value(i,1));
    }

    writeln(func(0,0));
}

