#include #include using namespace atcoder; using namespace std; using ll = long long; int main() { int N, K;cin >> N >> K; vector A(N); for (int i = 0;i < N;i++) cin >> A[i]; sort(A.begin(), A.end(), greater()); int res = 0; for (int bit = 1;bit < (1 << N);bit++) { if (!(bit & (1 << (N - 1)))) continue; int now = K; for (int i = 0;i < N;i++) if (bit & (1 << i)) now = now % A[i]; res = max(res, now); } cout << res << endl; }