#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]; } sort(A.rbegin(), A.rend()); ll ans = 0; ll Amin = A.back(); for (int i = 0; i < 1 << N; i++) { bitset<20> bit(i); ll tmp = K; for (int j = 0; j < N; j++) { if (bit[j]) { tmp %= A[j]; } } tmp %= Amin; chmax(ans, tmp); } cout << ans << endl; return 0; }