#include using namespace std; using ll=long long; using ull=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int GCD(int a,int b){ return b?GCD(b,a%b):a; } 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); if(N/K<=K){ rep(i,N/K) Ax = precK(Ax,Bx); return Ax.test(N%K); } else{ int g=0; rep(i,K) if(B[i]>=x) g=GCD(K-i,g); int p=-1; rep(i,K) if(A[i]>=x){ if(p==-1) p=i; else g=GCD(i-p,g); } if(p==-1) return false; return N%g==p%g; } } int main(){ scanf("%d%llu\n",&K,&N); 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; }