#include using namespace std; int main(){ int N, K; cin >> N >> K; vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } vector dp(1 << N, 0); dp[0] = K; for (int i = 0; i < (1 << N); i++){ for (int j = 0; j < N; j++){ if (!((i >> j) & 1)){ dp[i | (1 << j)] = max(dp[i | (1 << j)], dp[i] % A[j]); } } } cout << dp[(1 << N) - 1] << endl; }