let input = readLine()!.split(separator: " ").map { Int($0)! }
let N = input[0]
let K = input[1]
let A = readLine()!.split(separator: " ").map { Int($0)! }

let mostSignificantBit = String(1_000_000_000_000, radix: 2).count
var dp = [true: Optional<Int>.none, false: Optional<Int>.none]
dp[false] = 0

for i in stride(from: 0, to: mostSignificantBit, by: 1) {
    let mask = 1 << (mostSignificantBit - i - 1)

    var numberOfSetBit = 0
    for j in stride(from: 0, to: N, by: 1) {
        if A[j] & mask == mask {
            numberOfSetBit += 1
        }
    }

    let scoreWhen0 = mask * numberOfSetBit
    let scoreWhen1 = mask * (N - numberOfSetBit)

    var newDP = [true: Optional<Int>.none, false: Optional<Int>.none]

    [0, 1].forEach { digit in
        for isLessThanK in [false, true] {
            guard let previousValue = dp[isLessThanK]! else { continue }

            let nextIsLessThanK = isLessThanK || (K & mask > digit << (mostSignificantBit - i - 1))

            switch (isLessThanK, nextIsLessThanK) {
            case (true, true):
                newDP[nextIsLessThanK] = max(
                    newDP[nextIsLessThanK]! ?? 0,
                    previousValue + max(scoreWhen0, scoreWhen1)
                )
            case (false, true):
                guard digit == 0 else { continue } // この桁で初めてKを下回る、つまり1を選択することはない
                newDP[nextIsLessThanK] = max(
                    newDP[nextIsLessThanK]! ?? 0,
                    previousValue + scoreWhen0
                )
            case (false, false):
                guard K & mask == digit << (mostSignificantBit - i - 1) else { continue } // Kと同じ数字を選択する
                newDP[nextIsLessThanK] = max(
                    newDP[nextIsLessThanK]! ?? 0,
                    previousValue + (digit == 1 ? scoreWhen1 : scoreWhen0)
                )
            default:
                break
            }
        }
    }
    dp = newDP
}

print(max(dp[true]! ?? 0, dp[false]! ?? 0))
