import Foundation

class Scanner {
    static func readInt() -> Int {
        return Int(readLine()!)!
    }
    
    static func readIntArr() -> [Int] {
        return readLine()!.split(separator: " ").map { Int($0)! }
    }
    
    static func readM(_ n: Int) -> [[Int]] {
        var res = [[Int]]()
        for _ in 0..<n {
            res.append(readIntArr())
        }
        return res
    }
    
    static func readUknownIntMat() -> [[Int]] {
        var res = [[Int]]()
        while let line = readLine() {
            res.append(line.split(separator: " ").map { Int($0)! })
        }
        return res
    }
    
    static func readString() -> String {
        return readLine()!
    }
}

class Printer {
    static func printIntArray(_ arr: [Int]) {
        print(arr.map { String($0) }.joined(separator: " "))
    }
}
class Solution {
    func maxXXOR(_ arr: [Int], _ k: Int) -> Int {
        guard k > 0 else {
            return arr.reduce(0) { $0 + $1 }
        }
        let n = Int(log(Double(k))/log(Double(2))) + 1
        var res = 0
        for i in stride(from: 0, to: n, by: 1) {
            let c = 1<<i;
            var zcnt = 0, ocnt = 0
            for num in arr {
                if c&num != 0 {
                    ocnt += 1
                } else {
                    zcnt += 1
                }
            }
            if zcnt > ocnt { //we will set
                
            } else {
                
            }
            res += (max(zcnt, ocnt) * c)
        }
        return res
    }
}


let nk = Scanner.readIntArr()
let arr = Scanner.readIntArr()
print(Solution().maxXXOR(arr,nk[1]))
