import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") writef = lambda x: print("{:.12f}".format(x)) n,k,p = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() b.sort() from bisect import bisect_left as _bl, bisect_right as _br dl = {} dr = {} def bl(v): if v in dl: return dl[v] else: dl[v] = _bl(b, v) return dl[v] def br(v): if v in dr: return dr[v] else: dr[v] = _br(b,v) return dr[v] def sub(x): val = 0 for i in range(n): v = a[i] ind = bl(p-v) i0 = br(x-v) i1 = br(x+p-v) # print(v, ind, i0, i1, x) if i0>0: val += min(i0, ind) if i1>=ind: val += (i1-ind) if val>=k: return 0 return 1 l = -1 r = p+1 while abs(l-r)>1: m = (l+r)//2 if sub(m): l = m else: r = m ans = r print(ans)