#include using namespace std; using ll = long long; void chmax(ll& a, ll b){ if(a < b) a = b; } int main(){ ll K, N; cin >> K >> N; vector A(K), B(K); for(ll& a : A) cin >> a; for(ll& b : B) cin >> b; for(ll i = K; i < K * 3; i++){ ll x = LLONG_MIN; for(ll j = 0; j < K; j++) chmax(x, min(B[j], A.end()[j - K])); A.push_back(x); } cout << (N >= A.size() ? A.back() : A[N]) << endl; }