#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define All(v) (v).begin(), (v).end() #define pb push_back #define MP(a, b) make_pair((a), (b)) using ll = long long; using pii = pair; using pll = pair; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; int main() { int N, K; cin >> N >> K; vector A(N); rep(i, N) cin >> A[i]; sort(All(A)); reverse(All(A)); int res = 0; for(int bit = 0; bit < (1 << (N - 1)); bit++) { int num = K; rep(i, N - 1) { if(bit & (1 << i)) num %= A[i]; } res = max(res, num % A[N - 1]); } cout << res << endl; return 0; }