#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000000000001 vector get(vector a,vector b){ long long m = -Inf; rep(i,a.size()){ m = max(m,min(a[i],b[i])); } a.push_back(m); a.erase(a.begin()); return a; } int main(){ long long K,N; cin>>K>>N; vector A(K),B(K); rep(i,K)cin>>A[i]; rep(i,K)cin>>B[i]; if(N1LL){ long long mid = (ok+ng)/2; bitset<1001> a,b; rep(i,K){ if(A[i]>=mid){ a[i] = 1; } else{ a[i] = 0; } if(B[i]>=mid){ b[i] = 1; } else{ b[i] = 0; } } long long n = N; vector> temp(1,a); bool f = false; while(true){ if(n==0){ f=true; if(temp.back()[K-1])ok = mid; else ng = mid; break; } n--; bitset<1001> t = temp.back(); if((t & b).any()){ t >>= 1; t[K-1] = 1; } else{ t >>= 1; } rep(i,temp.size()){ if(temp[i]==t){ temp.erase(temp.begin(),temp.begin()+i); goto L; } } temp.push_back(t); } L:; if(!f){ if(temp[n%temp.size()][K-1])ok = mid; else ng = mid; } } cout<