use std::io::{stdin, Read}; fn main() { let mut buf = String::new(); stdin().read_to_string(&mut buf).unwrap(); let mut buf = buf.split_whitespace(); let mut get = || buf.next().unwrap().parse::().unwrap(); let n = get() as usize; let m = get() as usize; let mut xs = vec![]; let mut ys = vec![vec![]; 32]; let mut zs = vec![vec![]; n]; for _ in 0..n { xs.push(get()); } xs.sort(); for j in 0..n { let x = xs[j]; for i in 0..32 { if (x & (1 << i)) > 0 { ys[i].push(j); zs[j].push(i); } } } let mut fs = vec![false; n]; let mut bs = vec![0; 32]; let mut ans = vec![]; let mut v = 0; for i in 0..32 { let i = 31 - i; for &j in ys[i].iter() { if fs[j] { continue; } let x = xs[j]; fs[j] = true; v |= x; ans.push(x); for &k in zs[j].iter() { bs[k] += 1; } } } for i in 0..n { if fs[i] { continue; } let x = xs[i]; fs[i] = true; v |= x; ans.push(x); for &k in zs[i].iter() { bs[k] += 1; } } output(m, &ans); } fn output(m: usize, ans: &Vec) { for i in 0..m { if i > 0 { print!(" "); } print!("{}", ans[i]); } println!(); }