using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace AtCoder {
    public class Program {
        static int[] getKeys() {
            var Keys = Console.ReadLine().Split(' ');
            int N = Keys.Length;
            int[] Ns = new int[N];
            for (int i = 0; i < N; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }
        static int[] getKeys(char delimiter) {
            var Keys = Console.ReadLine().Split(delimiter);
            int N = Keys.Length;
            int[] Ns = new int[N];
            for (int i = 0; i < N; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }
        public static void Show<T>(T[,] map) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        public static void Show<T>(T[,] map, string delimiter) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + delimiter);
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        public static void Show<T>(IEnumerable<T> ts) {
            foreach (var item in ts) {
                Console.Write(item + " ");
            }
            Console.WriteLine();
        }
        public static void Show<T>(IEnumerable<T> ts, string delimiter) {
            foreach (var item in ts) {
                Console.Write(item + delimiter);
            }
            Console.WriteLine();
        }


        static void Main() {
            var input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            long K = long.Parse(input[1]);
            int digits = Convert.ToString(K, 2).Length;
            int[] isOne = new int[digits];
            input = Console.ReadLine().Split(' ');
            var Keys = new long[N];
            for (int i = 0; i < N; i++) {
                Keys[i] = long.Parse(input[i]);
                var bits = Convert.ToString(Keys[i], 2);
                int length = Math.Min(bits.Length, digits);
                for (int j = 0; j < length; j++) {
                    if (bits[bits.Length - j - 1] == '1') {
                        isOne[j]++;
                    }
                }
            }
            long X = 0;
            for (int i = 0; i < digits; i++) {
                if (isOne[i] < N - isOne[i]) {//多数決で0が多かった桁->1
                    X += (long)Math.Pow(2, i);
                }
            }
            if (X > K) {
                string Kbin = Convert.ToString(K, 2);
                string Xbin = Convert.ToString(X, 2);
                //               Console.WriteLine(Kbin);
                //               Console.WriteLine(Xbin);
                int errorBit = 0;
                for (int i = 0; i < Kbin.Length; i++) {
                    if (Xbin[i] - Kbin[i] > 0) {
                        errorBit = Kbin.Length - i - 1;
                        X -= (long)Math.Pow(2, Kbin.Length - i - 1);
                        if (X <= K) break;
                    }
                }
            }

            long answer = 0;
            for (int i = 0; i < N; i++) {
                //                Console.WriteLine("{0}^{1}={2}", X, Keys[i], X ^ Keys[i]);
                answer += X ^ Keys[i];
            }
            Console.WriteLine(answer);
        }
     static   void t() {
            long X = 32 + 16 + 8+2;
            long K = 32 + 4;
            string Kbin = Convert.ToString(K, 2);
            string Xbin = Convert.ToString(X, 2);
            //               Console.WriteLine(Kbin);
            //               Console.WriteLine(Xbin);
            int errorBit = 0;
            for (int i = 0; i < Kbin.Length; i++) {
                if (Xbin[i] - Kbin[i] > 0) {
                    errorBit = Kbin.Length - i - 1;
                    X -= (long)Math.Pow(2, Kbin.Length - i - 1);
                }
            }
            Console.WriteLine(X);
        }
    }
}


Measured memory_bytes: 32860