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


namespace debug
{
    class Program
    {
        static void Main(string[] args)
        {
            ProgramD a = new ProgramD();
            a.main();

        }
    }

    //ABC117
    class ProgramA
    {
        public void main()
        {
            string[] s = Console.ReadLine().Split(' ');
            double t = double.Parse(s[0]);
            double x = double.Parse(s[1]);

           Console.WriteLine(t/x);
        }
    }

    class ProgramB
    {
        public void main()
        {
            long n = long.Parse(Console.ReadLine());
            string[] xi = Console.ReadLine().Split(' ');

            int[] a = new int[n];

            for (int i = 0; i < n; i++)
                a[i] = int.Parse(xi[i]);

            Array.Sort(a);

            long sum = 0;

            for (int i = 0; i < n - 1; i++)
                sum += a[i];

            if(sum > a[n -1])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }

    class ProgramC
    {
        public void main()
        {
            string[] s = Console.ReadLine().Split(' ');
            string[] t = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long m = long.Parse(s[1]);

            long[] a = new long[m];
            long[] dis = new long[m -1];

            for (int i = 0; i < m; i++)
                a[i] = long.Parse(t[i]);

            //ソートする
            Array.Sort(a);
            
            //座標距離感を入れる
            for (int i = 0;i < m - 1;i++)
                dis[i] = a[i + 1] - a[i];
            

            //ソートする
            Array.Sort(dis);

            long ans = 0;
            //小さい順にm-n番目までが最小移動
            for (int i = 0;i < m - n;i++)
            {
                ans += dis[i];
            }
            Console.WriteLine(ans);
        }
    }

    class ProgramD
    {
        public void main()
        {
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]); 
            long k = long.Parse(s[1]);
            string[] t = Console.ReadLine().Split(' ');
            long[] a = new long[n];
            long[] num = new long[40];

            for (int i = 0; i < n; i++)
                a[i] = long.Parse(t[i]);

            //aの和を求める
            for (int i = 0; i < 40; i++)
                for (int j = 0; j < n; j++)
                    num[i] += (a[j] >> i) & 1;

            
            long max = 0;

            //ビット全探索的なやつ
            for(int i = 39;i >= 0;i--)
            {
                long sum = 0;
                if ((((k + 1) >> i) & 1) == 0)
                    continue;

                for (int j = 39; j >= 0; j--)
                {
                    if (j > i)
                    {
                        if ((((k + 1) >> j) & 1) == 1)
                            sum += (n - num[j]) * (long)Math.Pow(2, j);
                        else
                            sum += num[j] * (long)Math.Pow(2, j);
                    }
                    else if(i == j)
                    {
                        sum += num[j] * (long)Math.Pow(2, j);
                    }
                    else
                    {
                        if (n - num[j] > num[j])
                            sum += (n - num[j]) * (long)Math.Pow(2, j);
                        else
                            sum += num[j] * (long)Math.Pow(2, j);
                    }
                }

                
                if (sum > max)
                    max = sum;
            }

            Console.WriteLine(max);
        }

    }

    

}


Measured memory_bytes: 38524