use std::cmp; fn main() { let (n, k): (usize, usize) = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); ( iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap(), ) }; let a: Vec = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); let iter = buf.split_whitespace(); iter.map(|x| x.parse().unwrap()).collect() }; let mut dp = vec![0; 1 << n]; dp[0] = k; for _ in 0..n { for i in 0..n { for s in (0..(1 << n)).rev() { if ((1 << i) & s) != 0 { continue; } dp[(1 << i) | s] = { cmp::max( dp[(1 << i) | s], dp[s] % a[i], ) }; } } } let ans = dp[(1 << n) - 1]; println!("{}", ans); }