object Main extends App {
  import scala.io.StdIn._

  val Array(n, k) = readLine.trim.split(' ')
  val numbers = readLine.trim.split(' ').map(_.toLong)
  val bitCount = Array.tabulate(64){_ ⇒ 0}
  for (num ← numbers){
    for (i ← bitCount.indices) {
      if ((num & (1L << i)) != 0){
        bitCount(i) += 1
      }
    }
  }
  println(calMin(asBinaryDigit(k.toLong)))
  def asBinaryDigit(number: Long): List[Int] = {
    (0 until 64).reverse.map(i ⇒ if ((number & (1L << i)) != 0) 1 else 0).toList
  }
  def calMin(constraintDigits: List[Int]): Long = {
    val count = n.toInt
    def nonConstraint(digit: Int, result: Long = 0): Long = {
      digit match {
        case -1 ⇒ result
        case _ ⇒
          if (bitCount(digit) > count - bitCount(digit)) nonConstraint(digit - 1, result * 2 + bitCount(digit))
          else nonConstraint(digit - 1, result * 2 + count - bitCount(digit))
      }
    }
    def constraint(const: List[Boolean], digit: Int, prev: Long = 0): Long = {
      const match {
        case Nil ⇒ prev
        case true::t ⇒ List(constraint(t, digit - 1, prev * 2 + count - bitCount(digit)), nonConstraint(digit - 1, prev * 2 + bitCount(digit))).max
        case false::t ⇒ constraint(t, digit -  1, prev * 2 + bitCount(digit))
      }
    }
    constraint(constraintDigits.map(_ == 1), constraintDigits.length - 1)
  }
}