from bisect import * N, K, P = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) + [10 ** 18] A.sort(reverse=True) B.sort() no = -1 yes = P def check(m): cnt = 0 nowR, nowL = 0, 0 for a in A: while B[nowR] <= m - a: nowR += 1 while nowR - nowL: if B[nowL] < -a: nowL += 1 else: break cnt += nowR - nowL nowR, nowL = 0, 0 for a in A: while B[nowR] <= m - a + P: nowR += 1 while nowR - nowL: if B[nowL] < P - a: nowL += 1 else: break cnt += nowR - nowL return cnt >= K while yes - no != 1: mid = (yes + no)//2 if check(mid): yes = mid else: no = mid print(yes)