import sys import bisect input = sys.stdin.buffer.readline def solve(val): cnt = 0 for va in a: if va <= val: l = val - va r = p - va - 1 cnt += bisect.bisect_right(b, l) cnt += n - bisect.bisect_right(b, r) else: l = p - va r = l + val + 1 cnt += bisect.bisect_left(b, r) - bisect.bisect_left(b, l) return cnt n, k, p = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) b = sorted(b) ok = p ng = -1 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if solve(mid) >= k: ok = mid else: ng = mid print(ok)