#include int ri() { int n; scanf("%d", &n); return n; } int main() { int k = ri(); int64_t n; std::cin >> n; std::vector a(k); int64_t b[k]; for (auto &i : a) std::cin >> i; for (auto &i : b) std::cin >> i; for (int i = 0; i < 10000; i++) { int64_t next = -1000000000000000001; for (int j = 0; j < k; j++) next = std::max(next, std::min(b[j], a[i + j])); a.push_back(next); } if (n < (int) a.size()) { printf("%" PRId64 "\n", a[n]); return 0; } else { assert(0); int left = (n - (a.size() - k)) % k; printf("%" PRId64 "\n", a[a.size() - k + left]); } return 0; }