import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long K, long[] A) {
    alias toBins = (long x) => x.to!ulong
        .toChars!2
        .to!string
        .rightJustify(63, '0');
    
    auto a = A.map!toBins.array;
    auto k = toBins(K);
    bool lessThanK = false;
    string argmax;
    foreach (i; 0 .. 63) {
        if (!lessThanK && k[i] == '0') {
            argmax ~= "0";
            continue;
        }

        long zeros;
        long ones;
        foreach (b; a.transversal(i)) {
            if (b == '0') zeros++;
            if (b == '1') ones++;
        }

        if (zeros < ones) {
            argmax ~= "0";
            if (k[i] == '1')
                lessThanK = true;
        } else {
            argmax ~= "1";
        }
    }
    
    alias f = (long x) => A.map!(a => x ^ a).sum;

    return f(
        argmax
            .retro
            .enumerate
            .map!(t => t[1] == '1' ? 2 ^^ t[0] : 0)
            .sum);
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long K;
    K = input.front.to!long;
    input.popFront;

    long[] A = new long[](cast(size_t) (N));
    foreach (i; 0 .. cast(size_t) (N)) {
        A[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, K, A);
    else
        solve(N, K, A).writeln;
}
