#include #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; #define ll long long #define INF 9999999999999999 #define rep(i, m, n) for (int i = m; i < n; i++) #define rrep(i, m, n) for (int i = m - 1; i >= n; i--) #define pb(n) push_back(n) #define UE(N) N.erase(unique(N.begin(), N.end()), N.end()); #define Sort(n) sort(n.begin(), n.end()) #define Rev(n) reverse(n.begin(), n.end()) #define Out(S) cout << S << endl #define NeOut(S) cout << S #define HpOut(S) cout << setprecision(50) << S << endl #define Vec(K, L, N, S) vector K(N, S) #define DV(K, L, N, M, S) vector> K(N, vector(M, S)) #define TV(K, L, N, M, R, S) \ vector>> K(N, vector>(M, vector(R, S))) #define pint pair #define tint tuple #define paf(L, R) pair #define mod 1000000007 #define MAX 10000010 #define ALL(a) a.begin(), a.end() #define chmax(a, b) a = (((a) < (b)) ? (b) : (a)) #define chmin(a, b) a = (((a) > (b)) ? (b) : (a)) int main() { ios::sync_with_stdio(false); cin.tie(0); ll N, K; cin >> N >> K; vector A(N); rep(i, 0, N) cin >> A[i]; vector dp(1 << N, 0); //dp[S] := {S}の全ての要素を使ったとき余りの最大値 dp[0] = K; rep(i, 0, N) rep(bit, 0, 1 << N) rep(j, 0, N) chmax(dp[bit | 1 << j], dp[bit] % A[j]); cout << dp[(1 << N) - 1] << endl; }