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

namespace ABC117D
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt;
            var K = ReadLong;
            var A = ReadLongs;

            int log2k = 50;

            long[,] dp = new long[log2k + 1, 2]; //桁DP
            for (int i = 0; i < log2k + 1; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    dp[i, j] = -1;
                }
            }
            dp[0, 0] = 0;

            for (int digit = 0; digit < log2k; digit++)
            {
                long mask = 1L << (log2k - digit - 1);

                // 
                int count = 0;
                for (int i = 0; i < N; i++)
                {
                    if ((A[i] & mask) > 0) count++; //digit番目の桁が1である。
                }

                // コスト、Xへの影響
                long cost0 = mask * count;
                long cost1 = mask * (N - count);

                // smaller->smaller これより上の桁ですでに小さくなってしまっているため、これらは自由
                if (dp[digit, 1] != -1)
                {
                    dp[digit + 1, 1] = Math.Max(dp[digit + 1, 1], dp[digit, 1] + Math.Max(cost0, cost1));
                }

                // normal->smaller,normal
                if (dp[digit, 0] != -1)
                {
                    if ((K & mask) > 0) //kのdigit桁目が1
                    {
                        dp[digit + 1, 1] = Math.Max(dp[digit + 1, 1], dp[digit, 0] + cost0);
                        dp[digit + 1, 0] = Math.Max(dp[digit + 1, 0], dp[digit, 0] + cost1);
                    }
                    else
                    {
                        dp[digit + 1, 0] = Math.Max(dp[digit + 1, 0], dp[digit, 0] + cost0);
                    }
                }

            }
            Draw2D(dp);

            long ans = Math.Max(dp[log2k, 0], dp[log2k, 1]);
            Console.WriteLine(ans);
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] ReadLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        static public void Draw2D(long[,] map, long mode = 1)
        {
#if DEBUG
            long W = map.GetLength(0);
            long H = map.GetLength(1);

            long[,] map2 = new long[W + 1, H + 1];
            for (long i = 0; i < W + 1; i++)
            {
                for (long j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (long i = 0; i < W + 1; i++)
            {
                for (long j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 31324