#include using namespace std; using ll = long long; template using min_priority_queue = priority_queue, greater>; using pii = pair; using pll = pair; using Graph = vector>; const ll INF = 1LL << 60; template void chmax(T& a, T b) { if (b > a) a = b; } template void chmin(T& a, T b) { if (b < a) a = b; } template std::ostream& operator<<(std::ostream& os, const pair& x) noexcept { return os << "(" << x.first << ", " << x.second << ")"; } template void print_vector(vector a) { cout << '['; for (int i = 0; i < a.size(); i++) { cout << a[i]; if (i != a.size() - 1) { cout << ", "; } } cout << ']' << endl; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); ll N, K; cin >> N >> K; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } ll M = 1 << N; vector> dp(M, vector(N, -1)); for (int i = 0; i < N; i++) { dp[1 << i][i] = K % A[i]; } for (int bit = 0; bit < M; bit++) { for (int i = 0; i < N; i++) { if (!((bit >> i) & 1)) continue; for (int j = 0; j < N; j++) { if (((bit >> j) & 1)) continue; chmax(dp[bit | (1 << j)][j], dp[bit][i] % A[j]); } } } ll ret = 0; for (auto& v : dp[M - 1]) { chmax(ret, v); } std::cout << ret << "\n"; return 0; }