import numpy as np n, k, p = map(int, input().split()) A = np.array(input().split(), np.int64) B = np.array(input().split(), np.int64) A = np.sort(A) B = np.sort(B) def is_ok(x): cnt = 0 cnt += np.searchsorted(B, x-A, side='right').sum() cnt += np.searchsorted(B, p+x-A, side='right').sum() cnt -= np.searchsorted(B, p-A, side='left').sum() 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)