#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; using Graph = vector>; using ll = long long; typedef pair P_ll; typedef pair P; const ll INF_ll = 1e17; const int INF = 1e8; template bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template using min_priority_queue = priority_queue, greater>; int main() { ll N, K; cin >> N >> K; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector> dp(1 << N, vector(N, 0)); for (int i = 0; i < N; i++) { dp[1 << i][i] = K % A[i]; } for (int i = 0; i < 1 << N; i++) { for (int j = 0; j < N; j++) { if (((i >> j) & 1) == 0) { continue; } for (int k = 0; k < N; k++) { if (((i >> k) & 1) == 1) { continue; } int ni = i | (1 << k); chmax(dp[ni][k], dp[i][j] % A[k]); } } } ll ans = 0; for (int i = 0; i < N; i++) { chmax(ans, dp[(1 << N) - 1][i]); } cout << ans << endl; return 0; }