"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 => 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 => a ^ Xi).reduce((acc, cur) => cur + acc);

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

  console.log(max);
}

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