#include int ri() { int n; scanf("%d", &n); return n; } int gcd(int a, int b) { while (a && b) { if (a > b) a %= b; else b %= a; } return a + b; } int main() { int k = ri(); int64_t n; std::cin >> n; std::vector a(k + k); for (auto &i : a) std::cin >> i; std::reverse(a.begin() + k, a.end()); if (n < k) { printf("%" PRId64 "\n", a[n]); return 0; } int index[k + k]; std::iota(index, index + k + k, 0); std::sort(index, index + k + k, [&] (int i, int j) { return a[i] > a[j]; }); std::set start; std::set move; for (auto i : index) { if (i < k) start.insert(i); else move.insert(i - k + 1); if (!move.size()) continue; int g = 0; for (auto j : move) g = gcd(g, j); // std::cerr << "added " << i << std::endl; bool ok = false; if (n > k * k) { assert(0); for (auto i : start) if ((n - i) % g == 0) ok = true; } else { bool dp[k * k + 1]; memset(dp, 0, sizeof(dp)); for (auto i : start) dp[i] = true; for (int i = 0; i < k * k; i++) { if (!dp[i]) continue; for (auto j : move) if (i + j <= k * k) dp[i + j] = true; } if (dp[n]) ok = true; } if (ok) { printf("%" PRId64 "\n", a[i]); return 0; } } assert(0); return 0; }