#include using namespace std; #ifdef LOCAL #include "debug.h" #else #define DEBUG(...) #endif int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector a(n); for (auto&& e : a) cin >> e; sort(rbegin(a), rend(a)); int res = 0; for (int bt = 1; bt < 1 << n; ++bt) { int cur = k; for (int i = 0; i < n; ++i) { if (bt >> i & 1) { cur %= a[i]; } } cur %= a.back(); res = max(res, cur); } cout << res << '\n'; }