#[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 m = max_digit(&a, k);
    let mut dp = vec![vec![-1; 2]; MAX + 1];
    let mut K = vec![];
    if k == 0 {
        K.push(0);
    }
    while k > 0 {
        K.push(k % 2);
        k /= 2;
    }

    for _ in 0..m - K.len() {
        K.push(0);
    }

    K.reverse();
    dp[0][1] = 0;
    for (i, &e) in K.iter().enumerate() {
        let bit = 1 << (m - 1 - i);
        let mut zero = 0;
        let mut one = 0;

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

        // exact -> exact
        //if dp[i][1] != -1 {
        if e == 1 {
            dp[i + 1][1] = dp[i][1] + zero * bit;
        } else {
            dp[i + 1][1] = dp[i][1] + one * bit;
        }
        //}

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

    // for (i, e) in dp.iter().enumerate() {
    //     println!("{:?}", e);
    // }
    // println!("{:?}", K);
    // println!("{:b}", a[0]);
    println!("{}", max(dp[m][0], dp[m][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: 3916