/* Original Python code: N,K = list(map(int,input().split())) A = list(map(int,input().split())) INF = 10**18 dp = [set() for _ in range(1<>j & 1 == 1):continue next = i|(1< using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; long long K; cin >> N >> K; vector A(N); for (int i = 0; i < N; i++) cin >> A[i]; const long long INF = (long long)1e18; vector> dp(1 << N); dp[0].insert(K); for (int i = 0; i < (1 << N); i++) { if (dp[i].empty()) continue; for (int j = 0; j < N; j++) { if ((i >> j) & 1) continue; int nxt = i | (1 << j); for (long long k : dp[i]) { dp[nxt].insert(k % A[j]); } } } long long ans = -1; int full = (1 << N) - 1; for (long long x : dp[full]) { ans = max(ans, x); } cout << ans << "\n"; }