from bisect import bisect_left,bisect_right N,K = map(int,input().split()) X = list(map(int,input().split())) A = list(map(int,input().split())) INFTY = 2*10**17 M = 0 while pow(2,M)N: dpmin[m][i] = Amin[i] else: dpmin[m][i] = min(dpmin[m-1][i],dpmin[m-1][i+pow(2,m-1)]) def minq(i,j): d = j-i ans = INFTY ix = i for m in range(M,-1,-1): if d>>m & 1: ans = min(ans,dpmin[m][ix]) ix = ix+(1<N: dpmax[m][i] = Amax[i] else: dpmax[m][i] = max(dpmax[m-1][i],dpmax[m-1][i+pow(2,m-1)]) def maxq(i,j): d = j-i ans = -INFTY ix = i for m in range(M,-1,-1): if d>>m & 1: ans = max(ans,dpmax[m][ix]) return ans xmax = -INFTY xmin = INFTY K -= 1 ind_low = K ind_high = K+1 while True: low = minq(ind_low,ind_high) high = maxq(ind_low,ind_high) if xmin<=low and xmax>=high: break if xmin>low: xmin = low if xmax