#include using namespace std; using ll = long long; constexpr char newl = '\n'; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; ll K; cin >> n >> K; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end(), greater()); ll ans = 0; for (int i = 0; i < (1 << (n - 1)); i++) { ll res = K; for (int j = 0; j < n - 1; j++) { if (i >> j & 1) res %= a[j]; } res %= a.back(); ans = max(ans, res); } cout << ans << newl; return 0; }