#include using namespace std; using ll=long long; using ull=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) using BinArr = bitset<1000>; BinArr mask; int K; ll N; vector A,B; vector ValArr; BinArr precK(BinArr a, BinArr b){ BinArr res; rep(i,K) if(b.test(i)) res|=a>>i; BinArr res2; rep(i,K) if(b.test(i)) res2|=a<<(K-i); return res2 & mask; } bool solve(ll x){ BinArr Ax, Bx; rep(i,K) if(A[i]>=x) Ax.set(i); rep(i,K) if(B[i]>=x) Bx.set(i); rep(i,N/K) Ax = precK(Ax,Bx); return Ax.test(N%K); } int main(){ scanf("%d%llu\n",&K,&N); N = min(N/K,(ll)K)*K+(N%K); rep(i,K) mask.set(i); A.resize(K); rep(i,K) scanf("%lld",&A[i]); B.resize(K); rep(i,K) scanf("%lld",&B[i]); reverse(B.begin(),B.end()); rep(i,K) ValArr.push_back(A[i]); rep(i,K) ValArr.push_back(B[i]); int l=0, r=ValArr.size()+1; while(r-l>1){ int m=(l+r)/2; if(solve(ValArr[m])) l=m; else r=m; } printf("%lld\n",ValArr[l]); return 0; }