import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n;
    long k;
    scan(n, k);
    auto a = readln.split.to!(long[]);

    long ans;

    foreach (i ; 0 .. 50) {
        if (k & (1L << i)) {
            auto ks = k ^ (1L << i);
            auto mask = (1L << i) - 1;
            ks |= mask;

            auto res = solve(n, a, ks);

            debug {
                writefln("%08b", k);
                writefln("%08b", ks);
                writefln("res: %d", res);
            }
            ans = max(ans, solve(n, a, ks));
        }
    }

    ans = max(ans, solve(n, a, k));

    writeln(ans);
}

long solve(int n, long[] a, long k) {
    auto cnt = new int[](50);

    foreach (i ; 0 .. 50) {
        foreach (j ; 0 .. n) {
            if (a[j] & (1L << i)) {
                cnt[i]++;
            }
        }
    }

    long res;

    foreach (i ; 0 .. 50) {
        if (k & (1L << i)) {
            res += (1L << i) * max(cnt[i], n - cnt[i]);
        }
        else {
            res += (1L << i) * cnt[i];
        }
    }

    return res;
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
