K, N = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) def calc(): res = -10**18 for i in range(1, K+1): res = max(res, min(A[-i], B[-i])) return res for _ in range(K): A.append(calc()) if N <= len(A)-1: print(A[N]) quit() from heapq import heappop, heappush def check(x): AA = [a>=x for a in A] T = [] for i, b in enumerate(B): if b >= x: T.append(K - i) if len(T) == 0: return False t0 = T[0] Min = [-1] * t0 hq = [] for i in range(K, 2*K): if AA[i]: heappush(hq, (i, i%t0)) while hq: i, pos = heappop(hq) if Min[pos] != -1: continue Min[pos] = i for t in T: ii = (i+t) % t0 if Min[ii] == -1: heappush(hq, (i+t, ii)) return 0 <= Min[N%t0] <= N S = sorted(set(A + B)) if check(S[-1]): print(S[-1]) quit() ok = 0 ng = len(S) - 1 while ok+1 < ng: mid = (ok + ng) // 2 if check(S[mid]): ok = mid else: ng = mid print(S[ok])