#define DEBUGGING // Enables DEBUG macro. #include using namespace std; using i64 = long long; using u64 = unsigned long long; #define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i) #ifndef DEBUGGING #define debug(...) #define DEBUG(...) #else template void debug(T value) { std::cerr << value; } template void debug(T value, Ts... args) { std::cerr << value << ", "; debug(args...); } #define DEBUG(...) \ do { \ cerr << " (L" << __LINE__ << ") "; \ cerr << #__VA_ARGS__ << ": "; \ debug(__VA_ARGS__); \ cerr << endl; \ } while (0) #endif const i64 INF = 1LL << 40; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, K; cin >> N >> K; vector A(N); i64 mx = INF; for (auto& x : A) { cin >> x; mx = min(mx, x); } i64 ans = 0; REP(i, N) { i64 y = (K % A[i]) % mx; ans = max(ans, y); } cout << ans << endl; }