"use strict";

function XOR(a, X) {
  let strA = a.toString(2);
  let strX = X.toString(2);
  let max = Math.max(strA.length, strX.length);
  strA = "0".repeat(max - strA.length) + strA;
  strX = "0".repeat(max - strX.length) + strX;

  let result = "";
  for (let i = 0; i < max; i++) {
    if (strA[i] === strX[i]) {
      result += "0";
    } else {
      result += "1";
    }
  }
  return parseInt(result, 2);
}

function main(input) {
  const inputs = input.split("\n").filter(x => x !== "");

  const N = inputs[0].split(" ").map(Number)[0];
  const K = inputs[0].split(" ").map(Number)[1];
  const A = inputs[1].split(" ").map(Number);

  const sA = A.sort((a,b) => a-b);
  const maxA = sA[sA.length - 1];
  const maxDigit = maxA.toString(2).length;
  const strA = A.map(num => {
    let str = num.toString(2);
    return "0".repeat(maxDigit - str.length) + str;
  });


  let result = "";
  for (let i = 0; i < maxDigit; i++) {
    let count0 = 0;
    let count1 = 0;

    strA.forEach(str => {
      if (str[i] === "0") {
        count0++;
      } else {
        count1++;
      }
    })

    if (count0 > count1) {
      result += "1";
    } else {
      result += "0";
    }
  }

  let binK = K.toString(2);

  let max = A.map(a => XOR(a, 0)).reduce((acc, cur) => cur + acc);;
  // console.log({binK, result})
  for (let i = 0; i< binK.length; i++) {
    if (binK[i] === "1") {
      // console.log("binK.slice(0, i)", binK.slice(0, i));
      // console.log("result.slice(binK.length - i)", result.slice(binK.length - i));
      let binXi = binK.slice(0, i) + "0" + result.slice(result.length - (binK.length - i - 1));
      // console.log({binXi});
      let Xi = parseInt(binXi, 2);
      let fX = A.map(a => XOR(a, Xi)).reduce((acc, cur) => cur + acc);

      if (fX - max > 0) {
        max = fX;
      }
    }
  }

  console.log(max);
  // let anotherResult;
  // // console.log({result}, result.length);
  // if (result.length < dK) {
  //   result = "1".repeat(dK - result.length) + result;
  // } else {
  //   // console.log("goto else", {result})
  //   let strK = K.toString(2);
  //   strK = "0".repeat(result.length - strK.length) + strK;

  //   let newResult = "0";
  //   let newAnotherResult = "0";
  //   let newK = "0";
  //   for (let i = 0; i < result.length; i++) {
  //     if ( parseInt(newResult + result[i] ,2) > parseInt(newK + strK[i], 2) ){
  //       newResult += "0";

  //       let lastIndex = newAnotherResult.lastIndexOf("1");
  //       if (lastIndex > 0) {
  //         newAnotherResult = newAnotherResult.slice(0, lastIndex) + "0" + newAnotherResult.slice(lastIndex + 1);
  //         newAnotherResult += result[i];
  //       } else {
  //         newAnotherResult += "0";
  //       }
  //     } else {
  //       newResult += result[i];
  //       newAnotherResult += result[i];
  //     }
  //     newK += strK[i];
  //   }
  //   // console.log({newResult, newK})
  //   result = newResult;
  //   anotherResult = newAnotherResult;
  // }

  // let X = parseInt(result,2);
  // let X2 = parseInt(anotherResult,2);

  // // console.log({result, anotherResult, X, X2})

  // let fX = A.map(a => XOR(a, X)).reduce((acc, cur) => cur + acc);
  // let fX2 = A.map(a => XOR(a, X2)).reduce((acc, cur) => cur + acc);
  // console.log(Math.max(fX, fX2));

}

main(require("fs").readFileSync("/dev/stdin", "utf8"));