#include #include "atcoder/all" #define debug cout << "OK" << endl; template inline bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; } inline int Code(char c) { if ('A' <= c and c <= 'Z')return (int)(c - 'A'); if ('a' <= c and c <= 'z')return (int)(c - 'a'); if ('0' <= c and c <= '9')return (int)(c - '0'); assert(false); } using namespace std; using namespace atcoder; #define int long long constexpr int MOD = 998244353; constexpr int INF = (1LL << 62); using minit = modint998244353; template ostream& operator << (ostream& st, const vector &v) { for (const T value : v) { st << value << " "; } return st; } template istream& operator >> (istream& st, vector& v) { for (T &value : v) { st >> value; } return st; } // typedef struct { int to, cost; }edge; // void solve() { //#1 ε…₯εŠ› int N, K; cin >> N >> K; vector A(N); cin >> A; //#2 bitDP vector DP(1 << N, -1); DP[0] = K; for (int bit = 0; bit < (1ll << N) - 1; bit++) { for (int i = 0; i < N; i++) { if (bit & (1ll << i))continue; chmax(DP[bit | (1ll << i)], DP[bit] % A[i]); } } //#3 ε‡ΊεŠ› cout << DP.back() << endl; } signed main() { int T = 1; // cin >> T; for (int i = 0; i < T; i++) solve(); return 0; }