from bisect import bisect_left, bisect_right N, K, P = map(int, input().split()) As = list(map(int, input().split())) Bs = sorted(map(int, input().split())) def isok(m): cnt = 0 for A in As: cnt += bisect_right(Bs, m - A) # - bisect_left(Bs, - A) cnt += bisect_right(Bs, m - A + P) - bisect_left(Bs, - A + P) return cnt < K ok = -1 ng = P while ng - ok > 1: mid = (ok + ng) // 2 if isok(mid): ok = mid else: ng = mid print(ok + 1)