from bisect import bisect_left, bisect_right N, K, P = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) A.sort() B.sort() hi = P lo = 0 while hi - lo > 1: md = (hi + lo) >> 1 tmp = 0 for i, a in enumerate(A): if a < md: tmp += bisect_left(B, md - a) tmp += N - bisect_left(B, P - a) else: tmp += bisect_left(B, P + md - a) - bisect_left(B, P - a) if tmp < K: lo = md else: hi = md print(lo)