def pop_count(T): T = (T & 0x55555555) + ((T >> 1) & 0x55555555) T = (T & 0x33333333) + ((T >> 2) & 0x33333333) T = (T & 0x0F0F0F0F) + ((T >> 4) & 0x0F0F0F0F) T = (T & 0x00FF00FF) + ((T >> 8) & 0x00FF00FF) T = (T & 0x0000FFFF) + ((T >> 16) & 0x0000FFFF) return T def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) memo = {i: set() for i in range(N)} for bit in range(1, 1 << N): memo[pop_count(bit)-1].add(bit) dp = [0] * (1 << N) dp[0] = K for bitlist in memo.values(): for bit in bitlist: for j, a in enumerate(A): dp[bit] = max(dp[bit], dp[bit ^ (1 << j)] % a) print(dp[(1 << N) - 1]) if __name__ == "__main__": main()