from bisect import * N, K, P = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) B.sort() no = -1 yes = P def check(m): cnt = 0 for a in A: cnt += bisect_right(B, m - a) cnt += bisect_right(B, P + m - a) - bisect_left(B, P - a) return cnt >= K while yes - no != 1: mid = (yes + no)//2 if check(mid): yes = mid else: no = mid print(yes)