using AtCoderBeginnerContest117.Algorithms;
using AtCoderBeginnerContest117.Collections;
using AtCoderBeginnerContest117.Questions;
using AtCoderBeginnerContest117.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest117.Questions
{
    public class QuestionD : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var maxX = inputStream.ReadLongArray()[1];
            var a = inputStream.ReadLongArray();

            var fMax = new long[41, 2].SetAll((_, __) => long.MinValue);
            const int EqualOrOver = 0;
            const int Under = 1;

            fMax[40, 0] = 0;
            for (int digit = 39; digit >= 0; digit--)
            {
                long mask = 1L << digit;
                var ones = a.Count(ai => (ai & mask) > 0);

                if ((maxX & mask) > 0)
                {
                    // Eq -> Eq (di == 1)
                    AlgorithmHelpers.UpdateWhenLarge(ref fMax[digit, EqualOrOver], fMax[digit + 1, EqualOrOver] + mask * (a.Length - ones));
                    // Eq -> Under (di == 0)
                    AlgorithmHelpers.UpdateWhenLarge(ref fMax[digit, Under], fMax[digit + 1, EqualOrOver] + mask * ones);
                }
                else
                {
                    // Eq -> Eq (di == 0)
                    AlgorithmHelpers.UpdateWhenLarge(ref fMax[digit, EqualOrOver], fMax[digit + 1, EqualOrOver] + mask * ones);
                }

                // Under -> Under
                AlgorithmHelpers.UpdateWhenLarge(ref fMax[digit, Under], fMax[digit + 1, Under] + mask * ones);
                AlgorithmHelpers.UpdateWhenLarge(ref fMax[digit, Under], fMax[digit + 1, Under] + mask * (a.Length - ones));
            }

            yield return Math.Max(fMax[0, EqualOrOver], fMax[0, Under]);
        }
    }
}


namespace AtCoderBeginnerContest117
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionD();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);

            var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(writer);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
            Console.Out.Flush();
        }
    }
}

#region Base Class

namespace AtCoderBeginnerContest117.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }
}

#endregion

#region Algorithm

namespace AtCoderBeginnerContest117.Algorithms
{
    public static class AlgorithmHelpers
    {
        public static void UpdateWhenSmall<T>(ref T value, T other) where T : IComparable<T>
        {
            if (other.CompareTo(value) < 0)
            {
                value = other;
            }
        }

        public static void UpdateWhenLarge<T>(ref T value, T other) where T : IComparable<T>
        {
            if (other.CompareTo(value) > 0)
            {
                value = other;
            }
        }
    }

}

#endregion

#region Collections

namespace AtCoderBeginnerContest117.Collections
{
    public static class ArrayExtensions
    {
        public static T[] SetAll<T>(this T[] array, Func<int, T> func)
        {
            for (int i = 0; i < array.Length; i++)
                array[i] = func(i);
            return array;
        }

        public static T[,] SetAll<T>(this T[,] array, Func<int, int, T> func)
        {
            var length0 = array.GetLength(0);
            var length1 = array.GetLength(1);
            for (int i = 0; i < length0; i++)
                for (int j = 0; j < length1; j++)
                    array[i, j] = func(i, j);
            return array;
        }

        public static T[,,] SetAll<T>(this T[,,] array, Func<int, int, int, T> func)
        {
            var length0 = array.GetLength(0);
            var length1 = array.GetLength(1);
            var length2 = array.GetLength(2);
            for (int i = 0; i < length0; i++)
                for (int j = 0; j < length1; j++)
                    for (int k = 0; k < length2; k++)
                        array[i, j, k] = func(i, j, k);
            return array;
        }

        public static T[,,,] SetAll<T>(this T[,,,] array, Func<int, int, int, int, T> func)
        {
            var length0 = array.GetLength(0);
            var length1 = array.GetLength(1);
            var length2 = array.GetLength(2);
            var length3 = array.GetLength(3);
            for (int i = 0; i < length0; i++)
                for (int j = 0; j < length1; j++)
                    for (int k = 0; k < length2; k++)
                        for (int l = 0; l < length3; l++)
                            array[i, j, k, l] = func(i, j, k, l);
            return array;
        }
    }
}

#endregion

#region Extensions

namespace AtCoderBeginnerContest117.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);

    }
}

#endregion

Measured memory_bytes: 31324