#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; using pii = pair<int, int>; using pll = pair<ll, ll>; using Graph = vector<vector<int>>; const ll INF = 1LL << 60; template <class T> void chmax(T& a, T b) { if (b > a) a = b; } template <class T> void chmin(T& a, T b) { if (b < a) a = b; } template <typename T, typename S> std::ostream& operator<<(std::ostream& os, const pair<T, S>& x) noexcept { return os << "(" << x.first << ", " << x.second << ")"; } template <typename T> void print_vector(vector<T> 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<ll> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } ll M = 1 << N; sort(A.begin(), A.end()); reverse(A.begin(), A.end()); ll ret = 0; for (int bit = 0; bit < (1 << (N - 1)); ++bit) { std::vector<int> S; ll X = K; for (int i = 0; i < N; ++i) { if (bit & (1 << i)) X %= A[i]; } X %= A[N - 1]; chmax(ret, X); } std::cout << ret << "\n"; return 0; }