// https://n-o-n-o-n.github.io/library-cpp/ #include using namespace std; using ll = long long; template constexpr T inf() { return numeric_limits::max() / 2; } template bool chmin(T1 &a, T2 b) { return a > b ? a = b, true : false; } template bool chmax(T1 &a, T2 b) { return a < b ? a = b, true : false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, K; cin >> N >> K; vector A(N); for (auto &e : A) cin >> e; sort(A.begin(), A.end(), greater()); int ans = 0; for (int i = 0; i < 1 << N; i++) { int X = K; for (int j = 0; j < N; j++) { if (i >> j & 1) X = X % A[j]; } X = X % A[N - 1]; chmax(ans, X); } cout << ans << endl; }