import std.stdio, std.conv, std.string, std.range, std.typecons, std.format, core.bitop;
import std.algorithm.searching, std.algorithm.sorting, std.algorithm.iteration, std.algorithm.mutation;

void main()
{
    long[] input = readln().split.to!(long[]);
    long N = input[0];
    long K = input[1];
    long[] list = readln().split.to!(long[]);

    long x = 0;
    for(long i = 0;i < 41;i++)
    {
        int fragCount;
        foreach(e; list)
        {
            if((e&(1L<<i))!=0)
            {
                fragCount++;
            }
        }
        x |= (fragCount > list.length-fragCount?0:1L)<<i;
    }
    foreach_reverse(long i; 0..41)
    {
        if((x & (1L<<i)) < (K & (1L<<i)))
        {
            break;
        }
        if((x & (1L<<i)) > (K & (1L<<i)))
        {
            x &= ~(1L<<i);
        }
    }
    long sum;
    foreach(e; list)
    {
        sum += e^x;
    }
    writeln(sum);
}
