n, k, p = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) A.sort() B.sort() import bisect def is_ok(x): cnt = 0 for a in A: cnt += bisect.bisect_right(B, x-a) cnt += bisect.bisect_right(B, p+x-a)-bisect.bisect_left(B, p-a) return cnt >= k ng = -1 ok = p while ng+1 < ok: c = (ng+ok)//2 if is_ok(c): ok = c else: ng = c print(ok)