#[allow(unused_imports)]
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::Chars;
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused)]
const ALPHA_SMALL: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];
#[allow(unused)]
const ALPHA: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
#[allow(unused)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(unused)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(unused)]
fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
    let v: Vec<T> = read_vec();
    assert_eq!(v.len(), 2);
    (v[0], v[1])
}

/*
dp[i][0] := 上位の桁からi桁までを決定して，真にKより小さいことが確定しているf(X)の最大値
dp[i][1] := 上位の桁からi桁までを決定して，Kより小さいことが確定していないf(X)の最大値

// small -> small
dp[i+1][0] = max(dp[i][0] + one, dp[i][0] + zero)

// exacr -> small
// k[i]が１ならsmallにできる
if k[i] == 1
    dp[i+1][0] = max(dp[i+1][0], dp[i][1] + zero)
endif

// exact -> exact
if k[i] == 1
    dp[i+1][1] = dp[i][1] + one
else
    dp[i+1][1] = dp[i][1] + zero
endif
*/
const MAX: usize = 45;
fn main() {
    input!(n: usize, mut k: i64);
    input!(a: [i64; n]);
    let mut dp = vec![vec![-1; 2]; MAX + 1];

    // init
    dp[0][1] = 0;
    for i in 0..MAX {
        let mask = 1 << (MAX - 1 - i);
        let mut zero = 0;
        let mut one = 0;

        for &e in &a {
            if (e & mask) == 0 {
                zero += 1;
            } else {
                one += 1;
            }
        }
        // small -> small
        if dp[i][0] != -1 {
            dp[i + 1][0] = max(dp[i][0] + one * mask, dp[i][0] + zero * mask);
        }
        // exact -> small
        if dp[i][1] != -1 && (k & mask) != 0 {
            dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + one * mask);
        }

        // exact -> exact
        if dp[i][1] != -1 {
            if (k & mask) != 0 {
                dp[i + 1][1] = dp[i][1] + zero * mask;
            } else {
                dp[i + 1][1] = dp[i][1] + one * mask;
            }
        }

        //println!("{:b}", mask);
    }

    // for (i, e) in dp.iter().enumerate() {
    //     println!("{:?}", e);
    // }

    // println!("{:b}", a[0]);
    println!("{}", max(dp[MAX][0], dp[MAX][1]));
}

fn calc(a: &Vec<i64>, m: usize, i: usize) -> (usize, usize) {
    let mut one = 0;
    let mut zero = 0;
    let v = 1 << (m - 1 - i);
    for &e in a {
        if e & v == 0 {
            zero += 1;
        } else {
            one += 1;
        }
    }

    (zero, one)
}

fn digit(mut a: i64) -> usize {
    let mut ret = 0;
    while a > 0 {
        ret += 1;
        a /= 2;
    }

    ret
}

fn max_digit(a: &Vec<i64>, k: i64) -> usize {
    let mut ret = 0;
    for &e in a {
        ret = max(ret, digit(e));
    }
    ret = max(ret, digit(k));
    ret
}


Measured memory_bytes: 3976