#include using std::cin; using std::cout; using std::endl; using ll = long long; std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count()); template inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const int inf = (int)1e9 + 7; const long long INF = 1LL << 60; void solve() { int n, K; cin >> n >> K; std::vector a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } std::sort(a.rbegin(), a.rend()); a.erase(std::unique(a.begin(), a.end()), a.end()); n = (int)a.size(); ll res = 0; auto dfs = [&](auto &&self, int cur, ll val) -> void { if (cur == n - 1) { chmax(res, val % a[cur]); return; } self(self, cur + 1, val); self(self, cur + 1, val % a[cur]); }; dfs(dfs, 0, K); cout << res << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int I_love_KKT89 = 1; // cin >> I_love_KKT89; for (int Case = 1; Case <= I_love_KKT89; ++Case) { // cout << "Case #" << Case << ": "; solve(); } return 0; }