#include int ri() { int n; scanf("%d", &n); return n; } int main() { int k = ri(); int64_t n; std::cin >> n; int64_t a[k]; int64_t b[k]; for (auto &i : a) std::cin >> i; for (auto &i : b) std::cin >> i; if (n < k) { printf("%" PRId64 "\n", a[n]); return 0; } std::vector > mat(k, std::vector(k, -1000000000000000000)); for (int i = 0; i < k; i++) { mat[i][k - 1] = b[i]; if (i) mat[i][i - 1] = 1000000000000000000; } n -= (k - 1); for (; n; n >>= 1) { if (n & 1) { int64_t next[k]; for (auto &i : next) i = -1000000000000000000; for (int i = 0; i < k; i++) { for (int j = 0; j < k; j++) next[j] = std::max(next[j], std::min(a[i], mat[i][j])); } memcpy(a, next, sizeof(next)); } std::vector > next(k, std::vector(k, -1000000000000000000)); for (int i = 0; i < k; i++) { for (int j = 0; j < k; j++) { for (int l = 0; l < k; l++) { next[i][l] = std::max(next[i][l], std::min(mat[i][j], mat[j][l])); } } } mat = next; } printf("%" PRId64 "\n", a[k - 1]); return 0; }