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

    if(K==0)
    {
        long sum;
        sum = list.sum();
        writeln(sum);
    }

    long res = 0;
    int[] fragCountList;
    for(long i = bsr(K);i > 0;i--)
    {
        int fragCount;
        foreach(e; list)
        {
            if(((e&(1<<i))^(1<<i))!=0)
            {
                fragCount++;
            }
        }
        res |= (fragCount > list.length-fragCount?1:0)<<i;
        fragCountList = fragCount ~ fragCountList;
    }
    int i = 1;
    while(res > K)
    {
        res = res & ~(1<<i);
        i++;
    }
    long sum;
    long a;
    foreach(e; list)
    {
        sum += e^res;
    }
    writeln(sum);
}
