use std::io::BufRead;

pub struct StdinReader<R: BufRead> {
    pub buf_reader: R,
    pub buf: String,
}
impl<R: BufRead> StdinReader<R> {
    pub fn new(r: R) -> Self {
        StdinReader {
            buf_reader: r,
            buf: String::with_capacity(10000),
        }
    }
}

#[macro_export]
macro_rules! input {
    ($reader : expr, $t : ty) => { // one variable
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().parse().unwrap(); 
                reader.buf.clear();
                tmp_var
            },
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty) => { // 2 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0], tmp_var[1])
            }
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty, $t2 : ty) => { // 3 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0], tmp_var[1], tmp_var[2])
            }
        }
    };
    ($reader : expr, $t : ty; $size : expr) => { // Vector
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                tmp_var
            }
        }
    };
}
fn creates_bit_patterns(digit: usize) -> Vec<Vec<usize>> {
    let until = usize::pow(2, digit as u32);
    let mut v = Vec::with_capacity(until);
    for num in 0..until {
        v.push(creates_bit_pattern(num, digit));
    }
    return v;
}
fn creates_bit_pattern(mut num: usize, digit: usize) -> Vec<usize> {
    let mut v = Vec::with_capacity(digit);
    for _ in 0..digit {
        v.push(num % 2);
        num /= 2;
    }
    return v;
}

fn main() {
    let handle = std::io::stdin();
    let mut r = StdinReader::new(handle.lock());
    let (n, k) = input!(r, usize, usize);
    let all_a = input!(r, Vec<usize>; n);
    let mut memo: Vec<Vec<Option<usize>>> = vec![vec![None; 2]; 41];
    println!("{}", dp(39, 1, &memo, k, &all_a, n));
}

// all_ok == 1 is false all_ok == 0 is true
use std::cmp::max;
fn dp(d: usize, all_ok: usize, memo: &Vec<Vec<Option<usize>>>, k: usize, all_a: &Vec<usize>, n: usize) -> usize {
    let mut ans = 0;
    // cal
    let zero_count = all_a.iter().filter(|a| (**a >> d) % 2 == 0).count();
    if all_ok == 0 {
        if d == 0 {
            ans = max(
                zero_count * (2 as usize).pow(d as u32),
                (n - zero_count) * (2 as usize).pow(d as u32),
            );
        } else {
            ans = dp(d-1, 0, memo, k, all_a, n)
                + max(
                    zero_count *(2 as usize).pow(d as u32),
                    (n - zero_count) * (2 as usize).pow(d as u32),
                );
        }
    } else {
        if d == 0 {
            if (k >> d) % 2 == 1 {
                ans = max(zero_count * (2 as usize).pow(d as u32), (n - zero_count) * (2 as usize).pow(d as u32));
            } else {
                ans = (n - zero_count) * (2 as usize).pow(d as u32);
            }
        } else {
            if (k >> d) % 2 == 1 {
                let one_ans = dp(d-1, 1, memo, k, all_a, n) + zero_count * (2 as usize).pow(d as u32);
                let zero_ans = dp(d-1, 0, memo, k, all_a, n) + (n - zero_count) * (2 as usize).pow(d as u32);
                ans = max(one_ans, zero_ans);
            } else {
                ans = dp(d-1, 1, memo, k, all_a, n) + (n - zero_count) * (2 as usize).pow(d as u32);
            }
        }
    }
    return ans;
}


Measured memory_bytes: 6524