using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public static void Main()
    {
        long N = NextLong();
        long K = NextLong();
        string[] A = new string[N];
        int max = 0;
        for (int i = 0; i < N; i++)
        {
            long Ai = NextLong();
            A[i] = Convert.ToString(Ai, 2);
            max = Math.Max(A[i].Length, max);
        }
        int kl = Convert.ToString(K, 2).Length;
        kl = Math.Max(kl, max);
        for (int i = 0; i < N; i++) { A[i] = A[i].PadLeft(kl, '0'); }
        long X = 0;
        long ans = 0;
        for (int i = 0; i < kl; i++)
        {
            //Bit立ち
            int on = 0;
            for (int j = 0; j < N; j++)
            {
                if (A[j][i] == '1') on++;
            }
            //建てる時
            if (on * 2 < N)
            {
                if (X + (long)Math.Pow(2, (kl - i - 1)) <= K)
                {
                    X += (long)Math.Pow(2, (kl - i - 1));
                    ans += (N - on) * (long)Math.Pow(2, (kl - i - 1));
                }
                else {
                    ans += on * (long)Math.Pow(2, (kl - i - 1));
                }
            }
            else
            {
                //建てない場合は何も気にしない
                ans += on * (long)Math.Pow(2, (kl - i - 1));
            }
        }
        long X2 = 0;
        long ans2 = 0;
        for (int i = kl - 1; i != -1; i--)
        {
            //Bit立ち
            int on = 0;
            for (int j = 0; j < N; j++)
            {
                if (A[j][i] == '1') on++;
            }
            //建てる時
            if (on * 2 < N)
            {
                if (X2 + (long)Math.Pow(2, (kl - i - 1)) <= K)
                {
                    X2 += (long)Math.Pow(2, (kl - i - 1));
                    ans2 += (N - on) * (long)Math.Pow(2, (kl - i - 1));
                }
                else {
                    ans2 += on * (long)Math.Pow(2, (kl - i - 1));
                }
            }
            else
            {
                //建てない場合は何も気にしない
                ans2 += on * (long)Math.Pow(2, (kl - i - 1));
            }
        }


        Console.WriteLine(Math.Max(ans,ans2));
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); }
    public static string NextString() { Confirm(); return queue.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 44448