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]; 40];
    println!("{}", dp(39, 0, &mut memo, k, &all_a, n));
}

use std::cmp::max;
fn dp(d: usize, smaller: usize, memo: &mut Vec<Vec<Option<usize>>>, k: usize, all_a: &Vec<usize>, n: usize) -> usize {
    if let Some(ans) = memo[d][smaller] { return ans; }

    // cal
    let mut ans = 0;
    let zero_count = all_a.iter().filter(|a| (**a >> d) % 2 == 0).count();
    if smaller == 1 {
        if d == 0 {
            ans = max(
                zero_count * (1 << d),
                (n - zero_count) * (1 << d),
            );
        } else {
            ans = dp(d-1, 1, memo, k, all_a, n)
                + max(
                    zero_count * (1 << d),
                    (n - zero_count) * (1 << d),
                );
        }
    } else {
        if d == 0 {
            if (k >> d) % 2 == 1 {
                ans = max(zero_count * (1 << d), (n - zero_count) * (1 << d));
            } else {
                ans = (n - zero_count) * (1 << d);
            }
        } else {
            if (k >> d) % 2 == 1 {
                let one_ans = dp(d-1, 0, memo, k, all_a, n) + zero_count * (1 << d);
                let zero_ans = dp(d-1, 1, memo, k, all_a, n) + (n - zero_count) * (1 << d);
                ans = max(one_ans, zero_ans);
            } else {
                ans = dp(d-1, 0, memo, k, all_a, n) + (n - zero_count) * (1 << d);
            }
        }
    }
    memo[d][smaller] = Some(ans);    
    return ans;
}


Measured memory_bytes: 6396