#include #include #include using namespace std; int main() { int N, K; cin >> N >> K; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A.begin(), A.end()); int M = 1 << N; vector L = {K}; for (int i = 1; i >= 0; i--) { int a = A[i]; int len = L.size(); for (int j = 0; j < len; j++) { L.push_back(L[j] % a); } } int ans = 0; for (int x : L) { int alt = x % A[0]; if (ans < alt) { ans = alt; } } cout << ans << endl; return 0; }