#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define int long long #define rep(i, n) for (int i=0;i<(int)(n);++i) #define rep1(i, n) for (int i=1;i<=(int)(n);++i) #define rrep(i, n) for (int i=(int)(n)-1;i>=0;--i) #define rrep1(i, n) for (int i=(int)(n);i>=1;--i) #define range(i, l, r) for (int i=l;i<(int)(r);++i) #define rrange(i, l, r) for (int i=(int)(r)-1;i>=l;--i) #define unless(a) if(!(a)) #define all(a) begin(a),end(a) #define fst first #define scd second #define PB emplace_back #define PPB pop_back using vi=vector; using pii=pair; using vpii=vector; using ll=long long; constexpr int TEN(int n){return n==0?1:10*TEN(n-1);} templatebool chmin(T&a,T b){return a>b?(a=b,1):0;} templatebool chmax(T&a,T b){return a> N >> K; A.resize(N); rep(i, N) cin >> A[i]; sort(all(A), greater()); int mx = -inf; rep(S, 1 << (N - 1)) { if (S == 0) continue; int v = K; rep(i, N - 1) { if (S >> i & 1) v %= A[i]; } chmax(mx, v % A[N - 1]); } if (N == 1) { cout << N % A[0] << endl; } else { cout << mx << endl; } }