namespace D
{
    //begin using
    using System;
    using System.Text;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Globalization;
    using System.Numerics;

    //end using 

    class Solver
    {
        long[] cnt;
        int n;
        public void Solve()
        {
            n = cin.NextInt();
            long k = cin.NextLong();
            cnt = new long[40];

            for (int i = 0; i < n; i++)
            {
                long tmp = cin.NextLong();
                for (int j = 0; j < 40; j++)
                {
                    if (((tmp >> j) & 1) == 0) cnt[j] += 1;
                }
            }
            Console.WriteLine(calc(39, k));
        }
        long calc(int d, long k)
        {
            long ret = 0;
            if (((long)1 << (d + 1)) - 1 <= k)
            {
                long cf = 1;
                for (int i = 0; i <= d; i++)
                {
                    ret += cf * Math.Max(cnt[i], n - cnt[i]);
                    cf *= 2;
                }
                /* 
                Console.Write(" ");
                Console.Write(d);
                Console.Write(" ");
                Console.Write(k);
                Console.Write(" ");
                Console.WriteLine(ret);*/
                return ret;
            }
            ret = calc(d - 1, k) + (n - cnt[d]) * ((long)1 << d);
            if (((long)1 << (d)) <= k)
            {
                ret = Math.Max(ret, calc(d - 1, k - ((long)1 << d)) + cnt[d] * ((long)1 << d));
            }
            /*Console.Write(d);
            Console.Write(" ");
            Console.Write(k);
            Console.Write(" ");
            Console.WriteLine(ret); */
            return ret;
        }
        static Scanner<Stream> cin = new Scanner<Stream>(Console.OpenStandardInput());
        static Printer cout = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
        public static void Main(string[] args)
        {
            //var file = new Scanner<FileStream>(new FileStream("temp.txt", FileMode.Append));
            Console.SetOut(cout);
            new Solver().Solve();
            Console.Out.Flush();
        }
    }

    //begin auxiliary class
    public class Scanner<T>
    where T : Stream
    {
        public Scanner(T stream) { str = stream; }
        private readonly T str;
        private byte[] buf = new byte[1024];
        private int len, itr;
        public bool isEof = false;
        // public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) throw new EndOfStreamException();
            if (itr >= len)
            {
                itr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[itr++];
        }
        public char NextChar()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        public string NextString()
        {
            var sb = new StringBuilder();
            char c = NextChar();
            while (c >= 33 && c <= 126) { sb.Append(c); c = (char)read(); }
            return sb.ToString();
        }
        public long NextLong()
        {
            long ret = 0; byte b = 0; var negative = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { negative = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return negative ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int NextInt() { return (int)NextLong(); }
        public ulong NextUlong() { return ulong.Parse(NextString()); }
        public double NextDouble() { return double.Parse(NextString(), CultureInfo.InvariantCulture); }
        public decimal NextDecimal() { return decimal.Parse(NextString()); }
    }
    class Printer : StreamWriter
    {
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { }
    }
    //end auxiliary class
}


Measured memory_bytes: 13140