using System;
using System.Collections.Generic;
using System.Linq;



namespace CSharpSample01
{

    

    class Program
    {

        static int N;
        static long K;
        //Aの2進数表記
        static string[] B;
        static long[] A;
        //B_one[i] := Bの2進数ibit目の1の個数
        static int[] B_one;
        static long ans;
        
        //41bitの2進数に
        //O(41)
        static string Decimal_to_Binary(long deci)
        {
            
            string binary = "";
            int next_digi = 0;
            while (true)
            {
                long amari = deci % 2;
                if (amari == 0) binary = "0" + binary;
                else binary = "1" + binary;
                deci /= 2;
                next_digi++;
                if (deci == 0) break;
            }

            for(int i = next_digi; i <= 41; i++)
            {
                binary = "0" + binary;
            }

            return binary;
        }

        //10進数に
        //O(41)
        static long Binary_to_Decimal(string binary)
        {
            long rec = 0;
            binary = string.Join("", binary.Reverse());
            for(int i = 0; i < binary.Length; i++)
            {
                int v = binary[i] - '0';
                if(v == 1) rec += (long)Math.Pow(2, i);
            }

            return rec;
        }

        //A(10進)からB(2進)を作る
        //O(N)
        static void Create_B()
        {
            for (int i = 0; i < N; i++)
            {
                B[i] = Decimal_to_Binary(A[i]);
            }
        }

        //B_oneの更新
        //O(N * 41)
        static void Updata_B_one()
        {
            for(int i = 0; i < N; i++)
            {
                string binary = string.Join("", B[i].Reverse());
                for(int j = 0; j < binary.Length; j++)
                {
                    if (binary[j] == '1') B_one[j]++;
                }
            }
        }

        //O(41)
        static long Get_X()
        {
            ans = 0;
            long now_x = 0;
            int len = B[0].Length;
            for(int i = len - 1; i >= 0; i--)
            {
                char v;
                if (B_one[i] <= N - B_one[i])
                {                    
                    if (now_x + Math.Pow(2, i) <= K)
                    {
                        now_x += (long)Math.Pow(2, i);
                        v = '1';
                    }
                    else
                    {
                        v = '0';
                    }
                }
                else
                {
                    v = '0';
                }

                if (v == '1') ans += (long)Math.Pow(2, i) * (N - B_one[i]);
                else ans += (long)Math.Pow(2, i) * B_one[i];

            }
            
            return now_x;
        }

        
        static long XOR(string a, string b)
        {
            string result = "";
            
            for(int i = 0; i < a.Length; i++)
            {
                if (a[i] != b[i]) result += '1';
                else result += '0';
            }


            return Binary_to_Decimal(result);
        }

        static long F(long x)
        {
            long rec = 0;
            string x_binary = Decimal_to_Binary(x);

            for(int i = 0; i < N; i++)
            {
                rec += XOR(x_binary, B[i]);
            }

            return rec;
        }
        
        static void Main(string[] args)
        {
            //N, K, Aの入力
            string[] input = Console.ReadLine().Split(' ');
            N = int.Parse(input[0]);
            K = long.Parse(input[1]);
            A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            B = new string[N];
            B_one = new int[42];
            long X = 0;

            //Bを更新
            Create_B();          
            
            //B_oneを更新
            Updata_B_one();


            //Xを決める
            X = Get_X();

            //Console.WriteLine(F(X));
            Console.WriteLine(ans);
            
        }
    }
}

Measured memory_bytes: 41144