Arkady bought an air ticket from a city A to a city C. Unfortunately, there are no direct flights, but there are a lot of flights from A to a city B, and from B to C.

There are $n$ flights from A to B, they depart at time moments $a_1$, $a_2$, $a_3$, ..., $a_n$ and arrive at B $t_a$ moments later.

There are $m$ flights from B to C, they depart at time moments $b_1$, $b_2$, $b_3$, ..., $b_m$ and arrive at C $t_b$ moments later.

The connection time is negligible, so one can use the $i$-th flight from A to B and the $j$-th flight from B to C if and only if $b_j \ge a_i + t_a$.

You can cancel at most $k$ flights. If you cancel a flight, Arkady can not use it.

Arkady wants to be in C as early as possible, while you want him to be in C as late as possible. Find the earliest time Arkady can arrive at C, if you optimally cancel $k$ flights. If you can cancel $k$ or less flights in such a way that it is not possible to reach C at all, print $-1$.


-----Input-----

The first line contains five integers $n$, $m$, $t_a$, $t_b$ and $k$ ($1 \le n, m \le 2 \cdot 10^5$, $1 \le k \le n + m$, $1 \le t_a, t_b \le 10^9$) — the number of flights from A to B, the number of flights from B to C, the flight time from A to B, the flight time from B to C and the number of flights you can cancel, respectively.

The second line contains $n$ distinct integers in increasing order $a_1$, $a_2$, $a_3$, ..., $a_n$ ($1 \le a_1 < a_2 < \ldots < a_n \le 10^9$) — the times the flights from A to B depart.

The third line contains $m$ distinct integers in increasing order $b_1$, $b_2$, $b_3$, ..., $b_m$ ($1 \le b_1 < b_2 < \ldots < b_m \le 10^9$) — the times the flights from B to C depart.


-----Output-----

If you can cancel $k$ or less flights in such a way that it is not possible to reach C at all, print $-1$.

Otherwise print the earliest time Arkady can arrive at C if you cancel $k$ flights in such a way that maximizes this time.


-----Examples-----
Input
4 5 1 1 2
1 3 5 7
1 2 3 9 10

Output
11

Input
2 2 4 4 2
1 10
10 20

Output
-1

Input
4 3 2 3 1
1 999999998 999999999 1000000000
3 4 1000000000

Output
1000000003



-----Note-----

Consider the first example. The flights from A to B depart at time moments $1$, $3$, $5$, and $7$ and arrive at B at time moments $2$, $4$, $6$, $8$, respectively. The flights from B to C depart at time moments $1$, $2$, $3$, $9$, and $10$ and arrive at C at time moments $2$, $3$, $4$, $10$, $11$, respectively. You can cancel at most two flights. The optimal solution is to cancel the first flight from A to B and the fourth flight from B to C. This way Arkady has to take the second flight from A to B, arrive at B at time moment $4$, and take the last flight from B to C arriving at C at time moment $11$.

In the second example you can simply cancel all flights from A to B and you're done.

In the third example you can cancel only one flight, and the optimal solution is to cancel the first flight from A to B. Note that there is still just enough time to catch the last flight from B to C.

Difficulty: MEDIUM_HARD
Tags: Sorting

Amortized analysis

Complete search
Skill types: Sorting

Amortized analysis

Complete search

Starter code:

Solutions:
q = 1
for i in range(q):
	(n, m, t1, t2, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l1.append(10 ** 15)
	l2.append(10 ** 15)
	if k >= n:
		print(-1)
	else:
		ans = 0
		p = 0
		for i in range(k + 1):
			x = i
			b = l1[x] + t1
			while p < m and l2[p] < b:
				p += 1
			ans = max(ans, l2[min(m, p + k - i)] + t2)
		if ans >= 10 ** 15:
			print(-1)
		else:
			print(ans)


from bisect import bisect_left
(n, m, ta, tb, k) = (int(x) for x in input().split())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
ans = 0
if len(a) <= k or len(b) <= k:
	print(-1)
	return
for i in range(k + 1):
	v = bisect_left(b, a[i] + ta)
	if v + (k - i) < len(b):
		ans = max(ans, b[v + (k - i)] + tb)
	else:
		print(-1)
		return
print(ans)


(n, m, ta, tb, k) = map(int, input().split())
ar = [int(x) + ta for x in input().split()]
arr = [int(x) for x in input().split()]
r = [m] * n
aptr = 0
bptr = 0
while aptr < n and bptr < m:
	if arr[bptr] >= ar[aptr]:
		r[aptr] = bptr
		aptr += 1
	else:
		bptr += 1
if k >= n:
	print(-1)
else:
	ans = 0
	for p in range(0, k + 1):
		if r[p] + k - p >= m:
			ans = -1
			break
		else:
			ans = max(arr[r[p] + k - p] + tb, ans)
	print(ans)


(n, m, ta, tb, k) = map(int, input().split())
fa = list(map(int, input().split()))
fb = list(map(int, input().split()))
arrival = [x + ta for x in fa]
i = 0
j = 0
while k > 0:
	next = arrival[i]
	fb_time = fb[j]
	while fb_time < next:
		j += 1
		if j >= m:
			print(-1)
			exit()
		fb_time = fb[j]
	k -= 1
	i += 1
	if i >= n:
		print(-1)
		exit()
	j += 1
	if j >= m:
		print(-1)
		exit()
fb_time = arrival[i]
for k in range(j, m):
	if fb_time <= fb[k]:
		idex = k
		print(fb[k] + tb)
		exit()
print(-1)


import bisect
import sys
input = sys.stdin.readline
(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [i + ta for i in a]
ans = 0
for i in range(n):
	cancel = k - i
	if cancel >= 0:
		if cancel + bisect.bisect_left(b, a[i]) >= m:
			ans = -1
			break
		else:
			ans = max(b[cancel + bisect.bisect_left(b, a[i])], ans)
	else:
		break
if k >= min(n, m):
	ans = -1
if ans == -1:
	print(-1)
else:
	print(ans + tb)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def bs(a, l, h, x):
	while l < h:
		mid = (l + h) // 2
		if a[mid] == x:
			return mid
		if a[mid] < x:
			l = mid + 1
		else:
			h = mid
	return l

def sieve(a):
	for i in range(3, 10 ** 6 + 1, 2):
		a[i] = 1
	for i in range(3, 10 ** 6 + 1, 2):
		for j in range(i * i, 10 ** 6 + 1, i):
			a[j] = 0
	a[2] = 1
	return a

def solve():
	(n, m, ta, tb, k) = sep()
	a = lis()
	b = lis()
	if k >= n or a[k] + ta > b[m - 1] or k - 1 >= m:
		print(-1)
		return
	newtime = []
	for i in range(0, n):
		newtime.append([a[i] + ta, k - i])
	ans = 0
	for i in range(0, len(newtime)):
		if newtime[i][1] < 0:
			break
		ind = bs(b, 0, len(b), newtime[i][0])
		if ind + newtime[i][1] > m - 1:
			print(-1)
			return
		else:
			ans = max(ans, b[ind + newtime[i][1]] + tb)
	print(ans)
testcase(1)


import bisect
(n, m, ta, tb, k) = [int(i) for i in input().split(' ')]
arr1 = [int(i) for i in input().split(' ')]
arr2 = [int(i) for i in input().split(' ')]
t = 0
if k >= n or k >= m:
	t = -1
	print(t)
else:
	for a in range(k + 1):
		depa = arr1[a]
		arrb = depa + ta
		ind = bisect.bisect_left(arr2, arrb)
		ind = ind + k - a
		if ind >= m:
			t = -1
			break
		depb = arr2[ind]
		t = max(t, depb + tb)
	print(t)


from bisect import bisect_left

def main():
	buf = input()
	buflist = buf.split()
	n = int(buflist[0])
	m = int(buflist[1])
	ta = int(buflist[2])
	tb = int(buflist[3])
	k = int(buflist[4])
	buf = input()
	buflist = buf.split()
	a = list(map(int, buflist))
	buf = input()
	buflist = buf.split()
	b = list(map(int, buflist))
	if k >= n or k >= m:
		print(-1)
		return
	if bisect_left(b, a[0] + ta) == len(b):
		print(-1)
		return
	latest_arrival = b[bisect_left(b, a[0] + ta)] + tb
	for i in range(0, k + 1):
		if bisect_left(b, a[i] + ta) + (k - i) >= len(b):
			print(-1)
			return
		arrival = b[bisect_left(b, a[i] + ta) + (k - i)] + tb
		if arrival > latest_arrival:
			latest_arrival = arrival
	print(latest_arrival)
main()


from bisect import bisect_left as bl
(n, m, ta, tb, k) = [int(c) for c in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
if k >= n or k >= m:
	print('-1')
else:
	ans = -1
	for i in range(k + 1):
		avail = a[i] + ta
		pos = bl(b, avail)
		pos += k - i
		if pos > m - 1:
			ans = -1
			break
		ans = max(ans, b[pos] + tb)
	print(ans)


import sys

def LI():
	return list(map(int, sys.stdin.readline().split()))

def main():
	(n, m, ta, tb, k) = LI()
	a = LI()
	b = LI()
	if k >= n or k >= m:
		return -1
	r = 0
	bi = 0
	for i in range(k + 1):
		c = a[i] + ta
		while bi < m and b[bi] < c:
			bi += 1
		if bi + (k - i) >= m:
			return -1
		t = b[bi + (k - i)] + tb
		if r < t:
			r = t
	return r
print(main())


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_right(a, x)
	if i != len(a):
		return i
	else:
		return -1

def find_gt1(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(n, m, ta, tb, k) = In()
		l1 = list(In())
		l2 = list(In())
		ans = -1
		flag = 0
		if k >= n:
			flag = -1
		for x in range(n):
			temp = k - x
			if temp >= 0:
				cur_time = l1[x] + ta
				pos = find_gt1(l2, cur_time)
				if pos != -1:
					if pos + temp >= m:
						flag = -1
						break
					else:
						ans = max(ans, l2[pos + temp] + tb)
				else:
					flag = -1
					break
			else:
				break
		if flag == -1:
			print(-1)
		elif ans == 0:
			print(-1)
		else:
			print(ans)
	except:
		pass
M = 998244353
P = 1000000007
Inf = 1000000000000000000
for _ in range(1):
	main()


def gns():
	return [int(x) for x in input().split()]
(n, m, ta, tb, k) = gns()
ns = gns()
ms = gns()
ns = [x + ta + tb for x in ns]
ms = [x + tb for x in ms]
if k >= min(n, m):
	print(-1)
	quit()
ans = -1
j = 0
for i in range(k + 1):
	s = ns[i]
	while j < len(ms) and ms[j] < s:
		j += 1
	if j == len(ms):
		print(-1)
		quit()
	jj = j + k - i
	if jj >= m:
		print(-1)
		quit()
	ans = max(ans, ms[jj])
print(ans)


from bisect import bisect_left as bl
(n, m, ta, tb, k) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
for i in range(n):
	a[i] += ta
if k >= n:
	print(-1)
else:
	f = 0
	time = 0
	for i in range(0, k + 1):
		x = bl(b, a[i])
		pos = x + k - i
		if pos >= m:
			f = 1
			print(-1)
			break
		else:
			time = max(time, b[pos] + tb)
	if f == 0:
		print(time)


(n, m, ta, tb, k) = map(int, input().split())
a = [*map(int, input().split())]
b = [*map(int, input().split())]
a = [i + ta for i in a]
from bisect import bisect_left
ans = 0
if k >= min(n, m):
	print(-1)
	exit()
for i in range(k + 1):
	t = bisect_left(b, a[i])
	if t + k - i < m:
		ans = max(ans, b[t + k - i] + tb)
	else:
		ans = -1
		break
print(ans)


import sys
(n, m, ta, tb, k) = [int(i) for i in input().split(' ')]
a = [int(i) for i in input().split(' ')]
b = [int(i) for i in input().split(' ')]
if k >= len(a) or k >= len(b):
	print(-1)
	sys.exit()
a = [i + ta for i in a]
c = []
bIdx = 0
for i in a:
	while bIdx < len(b) and i > b[bIdx]:
		bIdx += 1
	c.append(bIdx)
m = 0
for i in range(len(c)):
	if i > k:
		break
	if c[i] + k - i > c[m] + k - m:
		m = i
bIdx = 0
while b[bIdx] < a[m]:
	bIdx += 1
	if bIdx == len(b):
		print(-1)
		sys.exit()
bIdx += k - m
if bIdx >= len(b):
	print(-1)
	sys.exit()
print(b[bIdx] + tb)


import bisect
(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if n <= k:
	print(-1)
	exit()
b_next = 0
ans = 0
for a_cancels in range(0, k + 1):
	a_start = a[a_cancels]
	b_arrive = a_start + ta
	while b_next < m and b[b_next] < b_arrive:
		b_next += 1
	b_cancels = k - a_cancels
	b_final_pos = b_next + b_cancels
	if b_final_pos >= m:
		print(-1)
		exit()
	ans = max(ans, b[b_final_pos] + tb)
print(ans)


from bisect import bisect_left
from sys import stdin

def solve():
	(n, m, ta, tb, k) = map(int, stdin.readline().split())
	A = [int(k) for k in stdin.readline().split()]
	B = [int(k) for k in stdin.readline().split()]
	if k >= n or k >= m:
		print(-1)
		return
	ans = 0
	i = 0
	while i < n and k >= 0:
		pos = bisect_left(B, A[i] + ta)
		if pos == m:
			ans = -1
			break
		if pos + k >= m:
			ans = -1
			break
		ans = max(ans, B[pos + k] + tb)
		i += 1
		k -= 1
	print(ans)
solve()


(n, m, ta, tb, k) = [int(i) for i in input().split()]
a = [int(i) + ta for i in input().split()]
b = [int(i) for i in input().split()]
(i, j) = (0, 0)
while k:
	if i == n - 1:
		print(-1)
		exit()
	nj = j
	while j < m and b[j] < a[i]:
		j += 1
	while nj < m and b[nj] < a[i + 1]:
		nj += 1
	j = nj + (nj == j)
	i += 1
	k -= 1
if j >= m:
	print(-1)
	exit()
print(b[j] + tb)


(n, m, ta, tb, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
i = 0
j = 0
while i < n and j < m:
	if b[j] >= a[i] + ta:
		d[i] = j
		i += 1
	else:
		j += 1
M = 0
for i in range(min(n, k) + 1):
	try:
		M = max(M, b[d[i] + k - i] + tb)
	except:
		M = -1
		break
print(M)


(n, m, ta, tb, k) = [int(x) for x in input().split()]
start_a = [int(x) for x in input().split()]
start_b = [int(x) for x in input().split()]
ans = 0
valid = -1
for i in range(m):
	if ans < n and start_a[ans] + ta <= start_b[i]:
		ans += 1
		k -= 1
		if k == -1:
			valid = start_b[i] + tb
			break
print(valid)


from bisect import bisect_left as lb
(n, m, x, y, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mx = 0
if k >= n or k >= m:
	exit(print(-1))
for i in range(k + 1):
	pos = lb(b, a[i] + x)
	if m - pos <= k - i:
		exit(print(-1))
	mx = max(mx, b[pos + (k - i)] + y)
print(mx)


(n, m, ta, tb, k) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
i = 0
for j in range(m):
	if i == n:
		print(-1)
		break
	if a[i] + ta <= b[j]:
		k -= 1
		i += 1
		if k < 0:
			print(b[j] + tb)
			break
else:
	print(-1)


import sys
input = sys.stdin.readline
(n, mm, ta, tb, k) = map(int, input().split())

def bsl(a, val):
	l = 0
	r = len(a) - 1
	ans = len(a)
	while l <= r:
		m = l + (r - l) // 2
		if a[m] == val:
			r = m - 1
			ans = m
		elif a[m] > val:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
maxi = -99
if k >= n:
	print(-1)
	exit(0)
for i in range(k + 1):
	j = bsl(b, a[i] + ta)
	if j + k - i >= mm:
		print(-1)
		exit(0)
	else:
		maxi = max(maxi, b[j + k - i] + tb)
print(maxi)


from sys import stdin
input = stdin.readline
(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	a[i] += ta
j = 0
out = -1
for i in range(m):
	if j < n and a[j] <= b[i]:
		j += 1
		k -= 1
		if k < 0:
			out = b[i] + tb
			break
print(out)


import bisect
(n, m, ta, tb, k) = map(int, input().split())
a = [int(num) + ta for num in input().split()]
b = list(map(int, input().split()))
if min(n, m) <= k:
	print(-1)
	exit()
i = j = 0
while i < n and j < m and k:
	if a[i] - b[j] <= 0:
		i += 1
		j += 1
		k -= 1
	else:
		j += 1
if k != 0 or j == m or i == n:
	print(-1)
elif a[i] > max(b[j:]):
	print(-1)
else:
	print(b[bisect.bisect_left(b, a[i], j)] + tb)


import bisect

def born_to_this(alist, blist, ta, tb, k):
	try:
		ans = -1
		for i in range(k + 1):
			ind = bisect.bisect_left(blist, alist[i] + ta)
			ind += k - i
			ans = max(ans, blist[ind] + tb)
	except:
		return -1
	return ans

def main():
	(n, m, ta, tb, k) = map(int, input().split())
	alist = list(map(int, input().split()))
	blist = list(map(int, input().split()))
	res = born_to_this(alist, blist, ta, tb, k)
	print(res)
main()


(n, m, ta, tb, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [i + ta for i in a]
i = 0
j = 0
ans = 0
for _k in range(k + 1):
	dk = _k
	i = 0
	if dk >= n:
		print(-1)
		return
	else:
		key = a[dk]
		dk = k - _k
		while j < m and b[j] < key:
			j += 1
		if j is m:
			print(-1)
			return
		elif m <= dk + j:
			print(-1)
			return
		else:
			ans = max(ans, b[j + dk] + tb)
print(ans)


from bisect import bisect_left
(n, m, ta, tb, k) = list(map(int, input().split()))
a = [int(x) + ta for x in input().split()]
b = [int(x) for x in input().split()]
if k >= len(a) or k >= len(b):
	print(-1)
	raise SystemExit(0)

def find_ge(a, x):
	i = bisect_left(a, x)
	if i != len(a):
		return i
	return None
ans = 0
for i in range(k + 1):
	t = a[i]
	j = find_ge(b, t)
	if j is None:
		print(-1)
		raise SystemExit(0)
	j += k - i
	if j >= len(b):
		print(-1)
		raise SystemExit(0)
	ans = max(ans, b[j] + tb)
print(ans)


def bs(num):
	low = 0
	high = m - 1
	while low < high:
		mid = (low + high) // 2
		if l2[mid] >= num:
			high = mid - 1
		else:
			low = mid + 1
	if l2[low] < num:
		return low
	else:
		return low - 1
(n, m, ta, tb, k) = map(int, input().split())
l1 = list(map(int, input().split()))
new = list(map(int, input().split()))
l2 = []
for i in new:
	if i >= l1[0] + ta:
		l2.append(i)
m = len(l2)
if k >= min(n, m):
	print(-1)
	exit()
ans = l2[k] + tb
for i in range(1, k + 1):
	num = l1[i]
	pos = bs(num + ta)
	if pos == m - 1 and l2[pos] < num + ta:
		print(-1)
		exit()
	if pos + k - i + 1 > m - 1:
		print(-1)
		exit()
	ans = max(ans, l2[pos + k - i + 1] + tb)
print(ans)


from bisect import bisect_left as bl
(n, m, ta, tb, k) = map(int, input().split())
a = [int(a) + ta for a in input().split()]
b = [int(a) for a in input().split()]
if min(n, m) <= k:
	print(-1)
else:
	ma = -1
	for i in range(k + 1):
		x = bl(b, a[i]) + k - i
		if x >= m:
			print(-1)
			break
		ma = max(ma, b[x])
	else:
		print(ma + tb)


import bisect
(q, w, x, y, z) = map(int, input().split())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
ans = 0
try:
	for i in range(z + 1):
		t = bisect.bisect_left(b, a[i] + x)
		tt = t + z - i
		ans = max(ans, b[tt])
	print(ans + y)
except:
	print(-1)


from bisect import bisect_left as bl
(n, m, t1, t2, k) = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(a) - t1 for a in input().split()]
if min(n, m) <= k:
	print(-1)
else:
	ma = -1
	for i in range(k + 1):
		x = bl(B, A[i]) + k - i
		if x >= m:
			print(-1)
			break
		ma = max(ma, B[x] + t1 + t2)
	else:
		print(ma)


import sys
from bisect import bisect_left as bl
(n, m, ta, tb, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split())) + [10 ** 10] * (k + 1)
if min(len(A), len(B)) <= k:
	print(-1)
	return
ans = -1
for (i, a) in enumerate(A[:k + 1]):
	xi = bl(B, a + ta)
	ans = max(ans, B[xi + k - i] + tb)
if ans >= 10 ** 10:
	print(-1)
	return
print(ans)


(n, m, x, y, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = 0
p = 0
m1 = 0
if k >= n or k >= m:
	print(-1)
else:
	for i in range(k + 1):
		s = a[i] + x
		for j in range(p, m):
			if s > b[j]:
				continue
			else:
				break
		else:
			j = m
		p = j
		q = p + k - i
		if q >= m:
			print(-1)
			exit()
		else:
			ans = b[q] + y
			if ans > m1:
				m1 = ans
	print(m1)


(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
j = 0
ans = -1
for i in range(m):
	if j < n and a[j] + ta <= b[i]:
		k -= 1
		j += 1
	if k < 0:
		ans = b[i] + tb
		break
	if j >= n:
		break
print(ans)


(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
s = list(map(int, input().split()))
if k >= n or k >= m:
	print(-1)
else:
	ans = -1
	for q in range(k + 1):
		start = a[q] + ta
		(l, r) = (-1, m)
		while r - l > 1:
			m1 = (l + r) // 2
			if start > s[m1]:
				l = m1
			else:
				r = m1
		if r + k - q < m:
			ans = max(ans, s[r + k - q] + tb)
		else:
			print(-1)
			break
	else:
		print(ans)


(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
import bisect
maxtime = 0
flag = 0
if k >= n or k >= m:
	print(-1)
else:
	for i in range(n):
		a[i] += ta
	for j in range(0, k + 1):
		x = bisect.bisect_left(b, a[j])
		if x + (k - j) >= m:
			flag = 1
			break
		else:
			maxtime = max(maxtime, b[x + (k - j)] + tb)
	if flag == 0:
		print(maxtime)
	else:
		print(-1)


import sys
(n, m, ta, tb, k) = [int(i) for i in input().split()]
a = [int(i) + ta for i in input().split()]
b = [int(i) for i in input().split()]
if n <= k or m <= k:
	print(-1)
	sys.exit()
aind = 0
bind = 0
mx = -1
while True:
	if b[bind] < a[aind]:
		bind += 1
		if bind == m:
			mx = -1
			break
	else:
		h = bind + k - aind
		if h >= m:
			mx = -1
			break
		mx = max(mx, b[h] + tb)
		aind += 1
		if aind == k + 1 or aind == n:
			break
print(mx)


import sys
from collections import Counter
import math
(n, m, t1, t2, k) = map(int, input().split())
l = list(map(int, input().split()))
for i in range(n):
	l[i] += t1
l1 = list(map(int, input().split()))
l.sort()
l1.sort()
a = 0
b = 0
i = 0
j = 0
maxx = 0
if k >= n or k >= m:
	print('-1')
	exit()
while i <= k:
	while j < m and l1[j] < l[i]:
		j += 1
	if j + k - i > maxx and j + k - i < m:
		maxx = j + k - i
	elif j + k - i > maxx and j + k - i >= m:
		print('-1')
		exit()
	i += 1
print(l1[maxx] + t2)


import bisect
(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if n - k <= 0 or m - k <= 0:
	print(-1)
elif n - k == 1 and a[n - 1] + ta > b[m - 1]:
	print(-1)
else:
	d = {}
	for i in range(n):
		j = bisect.bisect_left(b, a[i] + ta)
		d[a[i]] = j
	ma = -1
	flag = 1
	for i in range(k, -1, -1):
		kr = k - i
		if d[a[i]] + kr >= m:
			flag = 0
			break
		if d[a[i]] + kr <= m - 1 and b[d[a[i]] + kr] + tb > ma:
			ma = b[d[a[i]] + kr] + tb
	if flag:
		print(ma)
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
ans = 0
(n, m, ta, tb, k) = map(int, input().split())
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
if k >= n or k >= m:
	print(-1)
	sys.exit()
for i in range(k + 1):
	ind = countGreater(l1, m, l[i] + ta)
	ind = m - ind
	ind += k - i
	if ind >= m:
		print(-1)
		sys.exit()
	else:
		ans = max(ans, l1[ind] + tb)
print(ans)


from bisect import bisect_left
(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if n <= k:
	print(-1)
	exit()
ma = 0
for i in range(k + 1):
	p = a[i]
	q = k - i
	j = bisect_left(b, p + ta)
	if j + q >= m:
		print(-1)
		exit()
	ma = max(ma, b[j + q] + tb)
print(ma)


import bisect
(n, m, ta, tb, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
flg = 0
result = 0
if k >= min(m, n):
	flg = 1
	print(-1)
else:
	ar = [i + ta for i in a]
	x1 = []
	result = 0
	for i in range(n):
		x1.append(bisect.bisect_left(b, ar[i]))
		if i + m - x1[i] <= k:
			print(-1)
			flg = 1
			break
		j = k - i
		if j < 0:
			break
		result = max(result, b[x1[i] + j])
if flg == 0:
	print(result + tb)


(n, m, ta, tb, k) = map(int, input().split())
a = [int(i) + ta for i in input().split()]
b = [int(i) for i in input().split()]
j = 0
if k >= min(n, m):
	print(-1)
	exit()
while j < m and b[j] < a[0]:
	j += 1
if j == m:
	print(-1)
	exit()
ma = b[j] + tb
for i in range(k + 1):
	if m - j - k + i <= 0:
		print(-1)
		exit()
	else:
		ma = max(ma, b[j + k - i] + tb)
	while j < m and i + 1 < n and (b[j] < a[i + 1]):
		j += 1
print(ma)


def binsearch(arr, val, m, index1):
	l = index1
	r = m - 1
	while l <= r:
		mid = (l + r) / 2
		if arr[mid] == val:
			return mid
		elif mid > 0 and arr[mid] > val and (arr[mid - 1] < val):
			return mid
		elif arr[mid] > val:
			r = mid - 1
		else:
			l = mid + 1
	return -1
(n, m, ta, tb, k) = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
arr1.sort()
arr2.sort()
for i in range(n):
	arr1[i] += ta
i = 0
j = 0
count = 0
if k >= n or k >= m:
	print(-1)
else:
	i = 0
	j = 0
	ans = 0
	index = 0
	for i in range(k + 1):
		while j < m and arr2[j] < arr1[i]:
			j += 1
		if j + (k - i) >= m:
			print(-1)
			exit(0)
		ans = max(ans, arr2[j + (k - i)] + tb)
	print(ans)


(n, m, ta, tb, k) = [int(t) for t in input().split(' ')]
da = [int(t) for t in input().split(' ')]
db = [int(t) for t in input().split(' ')]
best = None
i = 0
j = 0
while i <= k and k < n:
	arrive = da[i] + ta
	while j < m and db[j] < arrive:
		j += 1
	b_cancel = k - i
	if j + b_cancel >= m:
		best = None
		break
	final = db[j + b_cancel] + tb
	best = max(final, best) if best is not None else final
	i += 1
print(-1 if best is None else best)


from bisect import bisect_left
(n, m, ta, tb, k) = map(int, input().split())
a = [int(X) + ta for X in input().split()]
b = [int(X) for X in input().split()]
an = -1
if k >= len(a) or k >= len(b):
	print(-1)
else:
	for i in range(k + 1):
		xx = bisect_left(b, a[i])
		if xx + k - i < m:
			an = max(b[xx + k - i] + tb, an)
		else:
			an = -1
			break
	print(an)


import sys
input = sys.stdin.readline
(n, m, ta, tb, k) = map(int, input().split())
a = [int(i) + ta for i in input().split()]
b = [int(i) for i in input().split()]
if k >= n or k >= m:
	print(-1)
	exit(0)
b = list(b)
q = 0
ans = -1
for i in range(k + 1):
	x = a[i]
	l = k - i
	while b[q] < x:
		q += 1
		if q >= m:
			print(-1)
			exit(0)
	try:
		ans = max(ans, b[q + l])
	except:
		print(-1)
		exit(0)
print(ans + tb)


import re, math, decimal, bisect

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]

def round(n):
	return int(n + 0.5)
DEBUG = 1

def debug(*args, **kwargs):
	if DEBUG:
		print(*args, **kwargs)
(n, m, ta, tb, k) = viread()
a = [x + ta for x in viread()]
b = viread()
flights = sorted([(ai + ta, 'a') for ai in a if ai <= b[-1]] + [(bi, 'b') for bi in b if bi > a[0]])
if k >= n or k >= m:
	print(-1)
	exit()
ktest = k
ans = -1
while ktest >= 0:
	aidx = ktest
	bidx = bisect.bisect_left(b, a[aidx])
	bidx += k - ktest
	if bidx >= len(b):
		print(-1)
		exit()
	ans = max(ans, b[bidx] + tb)
	ktest -= 1
print(ans)


import sys, os
import bisect
f = lambda : list(map(int, input().split()))
if 'local' in os.environ:
	sys.stdin = open('./input.txt', 'r')

def solve():
	(n, m, ta, tb, k) = f()
	a = f()
	b = f()
	if k >= n:
		print(-1)
		return
	first = k
	mnt = 0
	while first >= 0:
		second = k - first
		arrivebtime = a[first] + ta
		bstart_idx = bisect.bisect_left(b, arrivebtime)
		if bstart_idx + second >= m:
			print(-1)
			return
		mnt = max(mnt, b[bstart_idx + second] + tb)
		first -= 1
	print(mnt)
solve()


from bisect import bisect_left
(n, m, ta, tb, k) = map(int, input().split())
z = list(map(int, input().split()))
r = list(map(int, input().split()))
for i in range(len(z)):
	z[i] += ta
if k >= min(m, n):
	print(-1)
	exit()
inde = bisect_left(r, z[0])
if inde + k >= m:
	print(-1)
	exit()
mini = r[inde + k]
flag = 0
count = 1
while count <= k:
	inde = bisect_left(r, z[count])
	if inde + k - count >= m:
		print(-1)
		exit()
	else:
		mini = max(mini, r[inde + k - count])
	count += 1
print(mini + tb)


from sys import stdin, stdout
import bisect

def main():
	(n, m, ta, tb, k) = map(int, stdin.readline().split())
	a = [int(el) for el in stdin.readline().split()]
	b = [int(el) for el in stdin.readline().split()]
	ans = 0
	for i in range(n):
		temp = a[i] + ta
		ind = bisect.bisect_left(b, temp)
		if k < 0:
			break
		if ind == m:
			ans = -1
			break
		new = ind + k
		if new >= m:
			ans = -1
			break
		ans = max(ans, b[new] + tb)
		k -= 1
	if k >= 0:
		ans = -1
	print(ans)
main()


import os
import sys
from io import BytesIO, IOBase
from bisect import *

def main():
	(n, m, ta, tb, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if k >= n:
		print(-1)
	else:
		ma = 0
		for i in range(k, -1, -1):
			z = bisect_left(b, a[i] + ta)
			z += k - i
			if z >= m:
				ma = -1
				break
			ma = max(ma, b[z] + tb)
		print(ma)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def solve():
	(n, m, ta, tb, k) = num_input()
	arr = list_input()
	brr = list_input()
	ans = 0
	if k >= n or k >= m or k >= n + m:
		print(-1)
		return
	for i in arr:
		arrival = i + ta
		indx = bisect.bisect_left(brr, arrival)
		if indx + k >= m:
			print(-1)
			return
		else:
			ans = max(ans, brr[indx + k] + tb)
		k -= 1
		if k < 0:
			break
	print(ans)
t = 1
for _ in range(t):
	solve()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	(n, m, ta, tb, k) = LI()
	a = LI()
	b = LI()
	if k >= n or k >= m:
		return -1
	r = 0
	bi = 0
	for i in range(k + 1):
		c = a[i] + ta
		while bi < m and b[bi] < c:
			bi += 1
		if bi + (k - i) >= m:
			return -1
		t = b[bi + (k - i)] + tb
		if r < t:
			r = t
	return r
print(main())


(n, m, ta, tb, k) = map(int, input().split())
fa = list(map(int, input().split()))
fb = list(map(int, input().split()))
flighta = 0
flightb = 0
for i in range(n):
	fa[i] += ta
ans = 0
while k >= 0:
	if flighta == n or flightb == m:
		print(-1)
		quit()
	if fb[flightb] < fa[flighta]:
		flightb += 1
		continue
	if k == 0:
		ans = max(ans, fb[flightb])
		break
	if flightb + k >= m:
		print(-1)
		quit()
	ans = max(fb[flightb + k], ans)
	flighta += 1
	k -= 1
print(ans + tb)


from sys import stdin
import math
from collections import defaultdict
import bisect

def upper(arr, x, n):
	start = 0
	end = n
	while start < end:
		mid = (start + end) // 2
		if x > arr[mid]:
			start = mid + 1
		else:
			end = mid
	return start
I = stdin.readline
(n, m, ta, tb, k) = map(int, I().split())
a = [int(x) + ta for x in I().split()]
b = [int(x) for x in I().split()]
if k >= n or k >= m:
	print(-1)
else:
	ans = -1
	for i in range(k + 1):
		x = upper(b, a[i], m)
		ind = x + k - i
		if ind >= m:
			ans = -1
			break
		else:
			ans = max(ans, b[ind] + tb)
	print(ans)


import bisect
(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
try:
	for i in range(k + 1):
		j = bisect.bisect_left(b, a[i] + ta)
		ans = max(ans, b[j + k - i] + tb)
	print(ans)
except:
	print(-1)


(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if len(a) == k:
	print(-1)
	exit(0)
j = 0
ans = -1
for i in range(k + 1):
	while j < m and a[i] + ta > b[j]:
		j += 1
	if m - j + i <= k:
		print(-1)
		exit(0)
	ans = max(ans, b[j + k - i] + tb)
print(ans)


(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if n <= k:
	print(-1)
else:
	ind = 0
	maxx = -1
	for i in range(k + 1):
		arriv = a[i] + ta
		while ind < m and b[ind] < arriv:
			ind += 1
		if ind + (k - i) >= m:
			maxx = -1
			break
		else:
			maxx = max(maxx, b[ind + k - i] + tb)
	print(maxx)


import sys

def LI():
	return list(map(int, sys.stdin.readline().split()))

def main():
	(n, m, ta, tb, k) = LI()
	A = LI()
	B = LI()
	if k >= n or k >= m:
		return -1
	maxt = 0
	j = 0
	for i in range(k + 1):
		c = A[i] + ta
		while j < m and c > B[j]:
			j += 1
		if j + k - i >= m:
			return -1
		maxt = max(B[j + k - i] + tb, maxt)
	return maxt
print(main())


from bisect import bisect_left as br
(n, m, ta, tb, k) = map(int, input().split())
a = [int(e) + ta for e in input().split()]
b = [int(e) for e in input().split()]
if k >= min(m, n):
	print(-1)
else:
	a.sort()
	b.sort()
	(f, mx) = (0, -1)
	for i in range(0, k + 1):
		x = br(b, a[i])
		if x + k - i >= m:
			f = 1
		else:
			mx = max(mx, b[x + k - i])
	if f == 1:
		print(-1)
	else:
		print(mx + tb)


import bisect
(n, m, ta, tb, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if n <= k or m <= k:
	print(-1)
	exit(0)
t = 0
for i in range(0, k + 1):
	fb = bisect.bisect_left(b, a[i] + ta)
	if fb + k - i >= m:
		print(-1)
		exit(0)
	tt = b[fb + k - i] + tb
	t = max(t, tt)
print(t)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, OrderedDict
import math
import heapq
import bisect

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
(n, m, ta, tb, k) = listIn()
if k >= n or k >= m:
	print(-1)
else:
	a = listIn()
	b = listIn()
	B = [x + ta for x in a]
	mx = -1
	for i in range(n):
		if k - i >= 0:
			idx = bisect.bisect_left(b, B[i])
			if idx < m:
				i2 = idx + (k - i)
				if i2 < m:
					if mx < b[i2]:
						mx = b[i2]
				else:
					print(-1)
					exit(0)
			else:
				print(-1)
				exit(0)
		else:
			break
	if mx != -1:
		print(mx + tb)
	else:
		print(-1)


def bs(v: int):
	global n, m, ta, tb, k, a, b
	(l, r) = (-1, m - 1)
	while r - l > 1:
		mid = (l + r) // 2
		if b[mid] >= v:
			r = mid
		else:
			l = mid
	return r
(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
if k >= n or k >= m:
	print(-1)
	exit(0)
for cur in range(k + 1):
	pos = bs(a[cur] + ta)
	if pos + (k - cur) >= m:
		print(-1)
		exit()
	if b[pos + k - cur] < a[cur] + ta:
		print(-1)
		exit()
	ans = max(ans, b[pos + (k - cur)] + tb)
print(ans)


from bisect import *
i = lambda : [*map(int, input().split())]
try:
	(_, _, t, u, k) = i()
	a = i()
	b = i()
	print(max((u + b[bisect_left(b, a[x] + t) + k - x] for x in range(k + 1))))
except:
	print(-1)


import math
import sys
import bisect
(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if k >= min(n, m):
	print(-1)
	exit()
t = [i + ta for i in a]
p = 0
res = 0
for i in range(k + 1):
	tm = t[i]
	pos = bisect.bisect_left(b, t[i])
	if m - pos <= k - i:
		print(-1)
		exit()
	else:
		tm += b[pos + k - i] - t[i] + tb
	res = max(tm, res)
print(res)


(n, m, ta, tb, k) = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
res = -1
j = 0
if k < len(A):
	for i in range(k + 1):
		if i < len(A):
			t = A[i] + ta
			while j < len(B) and B[j] < t:
				j += 1
			togo = k - i
			jj = j + togo
			if jj < len(B):
				res = max(res, B[jj] + tb)
			else:
				res = -1
				break
print(res)


(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
land = a[0] + ta
ind = 0
while b[ind] < land and ind < m - 1:
	ind += 1
if ind + k >= m:
	print(-1)
elif k >= n:
	print(-1)
elif a[k] + ta > b[-1]:
	print(-1)
else:
	froma = k
	best = 0
	land = a[k] + ta
	while b[ind] < land:
		ind += 1
	for i in range(k + 1):
		best = max(best, b[ind + k - froma] + tb)
		froma -= 1
		land = a[froma] + ta
		while b[ind - 1] >= land and ind > 0:
			ind -= 1
	print(best)


import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
	return int(input())

def getList():
	return list(map(int, input().split()))
from bisect import bisect_left
(n, m, a, b, k) = getList()
anums = getList()
bnums = getList()
minpos = bnums[0] + b
maxpos = bnums[-1] + k
ans = 0
if k >= min(n, m):
	print(-1)
	sys.exit()
for (i, anum) in enumerate(anums):
	if i > k:
		break
	insert = bisect_left(bnums, anum + a)
	if insert + k - i >= m:
		print(-1)
		sys.exit()
	tmp = bnums[insert + k - i] + b
	if ans < tmp:
		ans = tmp
print(ans)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
from bisect import bisect_left as lower_bound, bisect_right as upper_bound

def so():
	return int(input())

def st():
	return input()

def mj():
	return map(int, input().strip().split(' '))

def msj():
	return map(str, input().strip().split(' '))

def le():
	return list(map(int, input().split()))

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def tr(n):
	return n * (n + 1) // 2

def main():
	for i in range(1):
		(a, b, c, d, e) = mj()
		L = le()
		P = le()
		if a >= b:
			h = b
		else:
			h = a
		if h > e:
			p = 0
			q = 0
			for u in range(1 + e):
				while b > p and P[p] < L[u] + c:
					p = p + 1
				if p + e >= u + b:
					print(-1)
					exit()
				q = max(d + P[p - u + e], q)
			print(q)
		else:
			print(-1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n, m, ta, tb, k) = gil()
(a, b) = (gil(), gil())
for i in range(n):
	a[i] += ta
i = bisect_left(b, a[0])
if i:
	b = b[i:]
if b:
	ans = -inf
	b.append(inf)
	a.append(inf)
	for i in range(n + 1):
		if i > k:
			break
		else:
			j = bisect_left(b, a[i])
			ans = max(ans, b[min(len(b) - 1, j + k - i)])
	print(ans + tb if abs(ans) != inf else -1)
else:
	print(-1)


import sys
from bisect import bisect_left
input = sys.stdin.readline

def ii():
	return int(input())

def mi():
	return map(int, input().rstrip().split())

def lmi():
	return list(map(int, input().rstrip().split()))

def li():
	return list(input().rstrip())

def __starting_point():
	(n, m, ta, tb, k) = mi()
	a = lmi()
	b = lmi()
	if n <= k or m <= k:
		print(-1)
		return
	a = [i + ta for i in a]
	lenb = len(b)
	a.sort()
	b.sort()
	ans = -10 ** 9
	for i in range(k + 1):
		if bisect_left(b, a[i]) + (k - i) >= lenb:
			print(-1)
			return
		else:
			ans = max(ans, b[bisect_left(b, a[i]) + (k - i)])
	print(ans + tb)
__starting_point()


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = 1
for _ in range(t):
	(n, m, ta, tb, k) = li()
	a = li()
	b = li()
	ans = 0
	for cancela in range(k + 1):
		if cancela >= n:
			ans = -1
			break
		cancelb = k - cancela
		nextflighttob = a[cancela]
		time = nextflighttob + ta
		flighttoc = bisect_left(b, time)
		if flighttoc + cancelb >= m:
			ans = -1
			break
		temp = 1
		if b[flighttoc] == time:
			temp = 0
		ans = max(ans, b[flighttoc + cancelb] + tb)
	print(ans)


(n, m, ta, tb, k) = map(int, input().split())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
if n <= k or m <= k:
	print(-1)
else:
	an = [i + ta for i in an]
	mta = 0
	c1 = 0
	c2 = 0
	for i in range(0, k + 1):
		c1 = i
		s = an[c1]
		while s > bn[c2]:
			c2 += 1
			if c2 + k - i >= m:
				break
		else:
			if bn[c2 + k - i] + tb > mta:
				mta = bn[c2 + k - i] + tb
		if c2 + k - i >= m:
			print(-1)
			break
	else:
		print(mta)


import bisect
(n, m, ta, tb, k) = map(int, input().split())
la = list(map(int, input().split()))
lb = list(map(int, input().split()))
la.sort()
lb.sort()
laa = [i + ta for i in la]
lbb = [i + tb for i in lb]
mx = -1
lol = 0
if k >= n or k >= m:
	lol = 1
else:
	for i in range(0, k + 1):
		a = laa[i]
		ind = bisect.bisect_right(lb, a)
		if ind - 1 + k - i < m and lb[ind - 1] == a:
			if mx < lbb[ind - 1 + (k - i)]:
				mx = lbb[ind - 1 + (k - i)]
		elif ind + (k - i) >= m and a != lb[-1]:
			lol = 1
			break
		elif ind + (k - i) >= m and a == lb[-1]:
			if mx < lbb[-1]:
				mx = lbb[-1]
		elif mx < lbb[ind + (k - i)]:
			mx = lbb[ind + (k - i)]
if lol == 1:
	print(-1)
else:
	print(mx)


(n, m, ta, tb, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
gone = 0
max_t = -1
if k >= n:
	print(-1)
else:
	for i in range(k + 1):
		flight_a = a[i]
		while gone < m and b[gone] < a[i] + ta:
			gone += 1
		j = gone + k - i
		if j >= m:
			max_t = -1
			break
		flight_b = b[j]
		max_t = max(max_t, flight_b + tb)
	print(max_t)


from sys import stdin
(n, m, ta, tb, k) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
i = 0
j = 0
tik = 0
maxi = 0
if n <= k or m <= k:
	print(-1)
elif True:
	for l in range(k + 1):
		while j < m and b[j] < a[l] + ta:
			j = j + 1
		f = k - l
		if j + f >= m:
			print(-1)
			tik = 1
			break
		elif b[j + f] > maxi:
			maxi = b[j + f]
	if tik == 0:
		print(maxi + tb)


from bisect import bisect
(na, nb, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if k >= min(na, nb):
	print(-1)
else:
	r = 0
	for i in range(k + 1):
		j = bisect(b, a[i] + ta - 1) + k - i
		if j < nb:
			r = max(j, r)
		else:
			print(-1)
			break
	else:
		print(b[r] + tb)


INF = 100000000
t = 1
for test in range(t):
	(n, m, ta, tb, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] + ta
	ans = 0
	ind = 0
	if k >= n or k >= m:
		print(-1)
		continue
	for i in range(k + 1):
		lo = a[i]
		while ind < m and b[ind] < lo:
			ind += 1
		if ind == m:
			ans = -1
			break
		else:
			if ind + k - i >= m:
				ans = -1
				break
			ans = max(ans, b[ind + (k - i)] + tb)
	print(ans)


def go():
	(n, m, ta, tb, k) = [int(i) for i in input().split(' ')]
	a = [int(i) + ta for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	j = 0
	answer = 0
	if k >= n or k >= m:
		return -1
	for i in range(k + 1):
		x = k - i
		while j < m and b[j] < a[i]:
			j += 1
		if j + x >= m:
			return -1
		answer = max(answer, b[j + x] + tb)
	return answer
print(go())


from sys import stdin

def input():
	return stdin.readline().strip()
(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	a[i] += ta
ca = 0
cb = 0
c = [-1] * n
i = 0
j = 0
while i < n and j < m:
	while (i < n and j < m) and a[i] > b[j]:
		j += 1
	if j < m:
		c[i] = j
	i += 1
ans = 0
for i in range(min(k + 1, n)):
	if c[i] == -1:
		ans = m
		break
	if c[i] + k - i > ans:
		ans = c[i] + k - i
if ans >= m or k >= min(n, m):
	print(-1)
else:
	print(b[ans] + tb)


from collections import *
from math import *
import array
import bisect
cin = lambda : [*map(int, input().split())]

def upper_bound(a, x):
	l = 0
	r = len(a) - 1
	while l < r:
		m = int((l + r + 1) / 2)
		if a[m] <= x:
			l = m
		else:
			r = m - 1
	return l
(n, m, ta, tb, k) = cin()
a = array.array('i', cin())
b = array.array('i', cin())
if k >= min(n, m):
	print('-1')
	exit()
ans = 0
try:
	for i in range(k + 1):
		l = bisect.bisect_left(b, a[i] + ta)
		l += k - i
		ans = max(ans, b[l] + tb)
	print(ans)
except:
	print('-1')


import math
(n, m, ta, tb, k) = [int(x) for x in input().split()]
ab = [int(x) for x in input().split()]
bc = [int(x) for x in input().split()]
maxi = -math.inf
j = 0
for i in range(k + 1):
	if k >= len(ab):
		maxi = -1
		break
	arrival = ab[i] + ta
	while j < len(bc):
		if bc[j] >= arrival:
			break
		j += 1
	if j + k - i >= len(bc):
		maxi = -1
		break
	if bc[j + k - i] + tb > maxi:
		maxi = bc[j + k - i] + tb
print(maxi)


def bbin(key, b):
	l = -1
	r = len(b)
	while r > l + 1:
		mm = (l + r) // 2
		if b[mm] >= key:
			r = mm
		else:
			l = mm
	return r
(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(k + 1):
	if i >= n:
		ans = -1
		break
	key = a[i] + ta
	rr = bbin(key, b) + k - i
	if rr >= m:
		ans = -1
		break
	ans = max(ans, b[rr] + tb)
print(ans)


(n, m, ta, tb, k) = map(lambda x: int(x), input().split())
aller = input().split()
retour = input().split()
for i in range(n):
	aller[i] = int(aller[i]) + ta
for i in range(m):
	retour[i] = int(retour[i])
l = 0
h = 0
maxx = 0
s = k
if n <= k or m <= k:
	print(-1)
else:
	for i in range(s + 1):
		h = 0
		for j in range(l, m):
			if retour[j] < aller[i]:
				h += 1
			else:
				break
		l += h
		k += h
		try:
			maxx = max(maxx, retour[k - i])
			ch = maxx + tb
		except:
			ch = -1
			break
	print(ch)


from bisect import bisect_left
(n, m, ta, tb, k) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
if k >= min(n, m):
	print(-1)
	return ()
ind_a = k
max_time = 0
while ind_a >= 0:
	ind_b = bisect_left(b, a[ind_a] + ta) + (k - ind_a)
	if ind_b >= m:
		print(-1)
		return ()
	curr_time = b[ind_b] + tb
	max_time = max(max_time, curr_time)
	ind_a -= 1
print(max_time)


def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
(n, m, ta, tb, k) = mi()
a = li()
b = li()
ans = -1
j = 0
if k < len(a):
	for i in range(k + 1):
		if i < len(a):
			t = a[i] + ta
			while j < len(b) and b[j] < t:
				j += 1
			tg = k - i
			jj = j + tg
			if jj < len(b):
				ans = max(ans, b[jj] + tb)
			else:
				ans = -1
				break
print(ans)


from bisect import bisect_left, bisect_right
for _ in range(1):
	(n, m, t_a, t_b, k) = map(int, input().split())
	a_b = list(map(int, input().split()))
	b_c = list(map(int, input().split()))
	for i in range(n):
		a_b[i] += t_a
	count = 0
	mini = -1
	if k >= n or k >= m:
		print(-1)
		continue
	for i in range(min(n, k + 1)):
		c = k - count
		if c >= 0:
			value = bisect_left(b_c, a_b[i])
			if value + c >= m:
				mini = -1
				break
			else:
				mini = max(mini, b_c[value + c] + t_b)
		if mini == -1:
			break
		count += 1
	print(mini)


import math
from collections import deque, defaultdict
from sys import stdin, stdout
import bisect
input = stdin.readline
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
(n, m, ta, tb, k) = mapin()
a = listin()
b = listin()
ans = 0
try:
	for i in range(k + 1):
		x = bisect.bisect_left(b, a[i] + ta)
		ans = max(ans, b[x + k - i] + tb)
	print(ans)
except:
	print(-1)


import bisect
(n, m, ta, tb, k) = map(int, input().split())
(*a,) = map(int, input().split())
(*b,) = map(int, input().split())
ans = -1
for ki in range(k + 1):
	if ki < n:
		bi = bisect.bisect_left(b, a[ki] + ta) + k - ki
		if bi < m:
			ans = max(ans, b[bi] + tb)
		else:
			ans = -1
			break
	else:
		ans = -1
		break
print(ans)


from sys import stdin, exit
from bisect import bisect_left
input = stdin.readline
(n, m, ta, tb, k) = map(int, input().split())
t1 = list(map(int, input().split()))
t2 = list(map(int, input().split()))
if k >= min(n, m):
	print(-1)
	exit(0)
res = 0
i = k
while i >= 0:
	j = bisect_left(t2, t1[i] + ta) + k - i
	if j >= m:
		print(-1)
		exit(0)
	res = max(res, t2[j] + tb)
	i -= 1
print(res)


(n, m, a, b, k) = map(int, input().split())
arr = []
brr = []
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
t = min(n, m)
q = -1
if t <= k:
	print(q)
	exit()
x = arr[k] + a
y = brr[m - 1]
if x > y:
	print(q)
	exit()
else:
	crr = []
	ind = 0
	for i in range(0, k + 1):
		u = arr[i] + a
		for j in range(ind, len(brr)):
			v = k - i
			if brr[j] >= u:
				ind = j
				if v >= len(brr) - j:
					print(q)
					exit()
				else:
					crr.append(j + v)
					break
z = max(crr)
print(brr[z] + b)


import os

def _f(n, m, ta, tb, k, a_arr, b_arr):
	fa_arr = list(map(lambda x: x + ta, a_arr))
	fb_arr = list(map(lambda x: x + tb, b_arr))
	try:
		prev_i = 0
		r = 0
		for tk in range(k + 1):
			fa = fa_arr[tk]
			i = prev_i
			while b_arr[i] < fa:
				i += 1
			tail = k - tk
			prev_i = i
			i += tail
			r = max(r, fb_arr[i])
	except IndexError:
		return -1
	return r

def f(n, m, ta, tb, k, a_arr, b_arr):
	return _f(n, m, ta, tb, k, a_arr, b_arr)
if os.environ.get('DEBUG', False):
	print(f'{f(4, 5, 1, 1, 2, [1, 3, 5, 7], [1, 2, 3, 9, 10])} = 11')
	print(f'{f(2, 2, 4, 4, 2, [1, 10], [10, 20])} = -1')
	print(f'{f(4, 3, 2, 3, 1, [1, 999999998, 999999999, 1000000000], [3, 4, 1000000000])} = 1000000003')
	print(f'{f(4, 5, 1, 1, 4, [1, 3, 5, 7], [1, 2, 3, 9, 10])} = -1')
	print(f'{f(4, 5, 1, 1, 3, [1, 3, 5, 7], [1, 2, 3, 9, 10])} = -1')
else:
	(n, m, ta, tb, k) = list(map(int, input().split()))
	a_arr = list(map(int, input().split()))
	b_arr = list(map(int, input().split()))
	print(f(n, m, ta, tb, k, a_arr, b_arr))


(n, m, a, b, k) = [int(x) for x in input().split()]
a1 = [(int(x) + a, 1) for x in input().split()]
b1 = [(int(x), 2) for x in input().split()]
c = sorted(a1[:] + b1[:])
counter = count1 = count2 = 0
for item in c:
	if item[1] == 1:
		count1 += 1
	else:
		count2 += 1
	if item[1] == 2:
		if count1 > k and count2 > k and (counter == k):
			print(item[0] + b)
			break
		else:
			counter = min(counter + 1, count1, count2)
else:
	print(-1)


(m, n, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if m <= k:
	print(-1)
else:
	ans = 0
	count = 0
	bef = 0
	for i in range(m):
		now = a[i]
		for j in range(bef, n):
			if b[j] < a[i] + ta:
				if j == n - 1:
					j += 1
				pass
			else:
				break
		if count > k:
			break
		if j == n:
			ans = 0
			break
		if k - count < n - j:
			ans = max(ans, b[j + k - count] + tb)
		else:
			ans = 0
			break
		bef = j
		count += 1
	if ans == 0:
		print(-1)
	else:
		print(ans)


(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if k >= n or k >= m:
	print(-1)
	exit()
arr = []
for i in range(n):
	arr.append(a[i] + ta)
arr.append(100000000000000)
mm = -1
for i in range(0, min(n, k) + 1):
	rem = k - i
	start = 0
	end = m - 1
	ans = 10000000
	while start <= end:
		mid = start + end >> 1
		if b[mid] >= arr[i]:
			end = mid - 1
			ans = min(ans, mid)
		else:
			start = mid + 1
	if ans + rem >= m:
		print(-1)
		exit()
	else:
		mm = max(mm, b[ans + rem] + tb)
print(mm)


(n, m, ta, tb, k) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if k >= min(n, m):
	print(-1)
else:
	result = -1
	for i in range(k + 1):
		num = A[i] + ta
		left = -1
		right = m
		while left + 1 != right:
			mid = (left + right) // 2
			if B[mid] >= num:
				right = mid
			else:
				left = mid
		end = right + k - i
		if end < m:
			result = max(result, B[end] + tb)
		else:
			print(-1)
			break
	else:
		print(result)


(n, m, ta, tb, k) = list(map(int, input().split()))
j = 0
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = 0
if k >= min(n, m):
	t = -1
else:
	for i in range(k + 1):
		while j < m and b[j] < a[i] + ta:
			j += 1
		if j + k - i >= m:
			t = -1
			break
		t = max(t, b[j + k - i] + tb)
print(t)


def dostuff(n, m, ta, tb, k):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(bs, ans) = (0, 0)
	for ai in range(k + 1):
		try:
			while b[bs] < a[ai] + ta:
				bs += 1
		except IndexError:
			print(-1)
			return None
		bi = k - ai
		try:
			if ans < b[bs + bi] + tb:
				ans = b[bs + bi] + tb
		except IndexError:
			print(-1)
			return None
	print(ans)
(n, m, ta, tb, k) = map(int, input().split())
dostuff(n, m, ta, tb, k)


from bisect import bisect_left
ln = [int(i) for i in input().split(' ')]
n = ln[0]
m = ln[1]
t1 = ln[2]
t2 = ln[3]
k = ln[4]
f1 = [int(i) for i in input().split(' ')]
f2 = [int(i) for i in input().split(' ')]
if k >= n or k >= m:
	print(-1)
else:
	m = 0
	ans = 0
	for i in range(0, k + 1):
		flt = f1[i] + t1
		if flt > f2[-1]:
			ans = -1
		ind = bisect_left(f2, flt)
		if k - i >= len(f2) - ind:
			ans = -1
		ltind = min(ind + (k - i), len(f2) - 1)
		m = max(m, f2[ltind] + t2)
	if ans == -1:
		print(-1)
	else:
		print(m)


from sys import stdin
from bisect import bisect_left as bl
(n, m, ta, tb, k) = map(int, stdin.readline().strip().split())
s = list(map(int, stdin.readline().strip().split()))
s1 = list(map(int, stdin.readline().strip().split()))
ans = -1
for i in range(min(k + 1, n)):
	x = s[i] + ta
	ind = bl(s1, x)
	y = ind + k - i
	if y >= m:
		ans = -1
		break
	if s1[y] >= x:
		ans = max(s1[y] + tb, ans)
if n <= k:
	ans = -1
print(ans)


(n, m, ta, tb, k) = map(int, input().split())
b = sorted(map(lambda x: int(x) + ta, input().split()))
c = sorted(map(int, input().split()))
i = j = 0
while k > 0 and i < n and (j < m):
	while j < m and c[j] < b[i]:
		j += 1
	if i < n and j < m:
		k -= 1
		i += 1
		j += 1
if i == n or j == m:
	print(-1)
else:
	for k in range(j, m):
		if b[i] <= c[k]:
			print(c[k] + tb)
			break
	else:
		print(-1)


import os
from bisect import bisect_left
from math import inf
if os.getenv('SJDEAK'):
	debug = print
else:
	debug = lambda *args, **kwargs: None
(N, M, Ta, Tb, K) = list(map(int, input().split()))
arriveAts = list(map(lambda s: int(s) + Ta, input().split()))
flights = list(map(int, input().split()))
ansI = -inf
for (i, arriveAt) in enumerate(arriveAts[:K + 1]):
	nearestFlightIndex = bisect_left(flights, arriveAt)
	ansI = max(ansI, nearestFlightIndex + (K - i))
	debug('i, arriveAt, nearestFlightIndex, ansI:', i, arriveAt, nearestFlightIndex, ansI)
print(-1 if K >= N or ansI == -inf or ansI > M - 1 else flights[ansI] + Tb)


import bisect
(n, m, x, y, k) = map(int, input().split())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
ans = 0
try:
	for i in range(0, k + 1):
		t = bisect.bisect_left(b, a[i] + x)
		tt = t + k - i
		ans = max(ans, b[tt] + y)
	print(ans)
except:
	print(-1)


from bisect import bisect_left, bisect_right

class Result:

	def __init__(self, index, value):
		self.index = index
		self.value = value

class BinarySearch:

	def __init__(self):
		pass

	@staticmethod
	def greater_than(num: int, func, size: int=1):
		if isinstance(func, list):
			index = bisect_right(func, num)
			if index == len(func):
				return Result(None, None)
			else:
				return Result(index, func[index])
		else:
			(alpha, omega) = (0, size - 1)
			if func(omega) <= num:
				return Result(None, None)
			while alpha < omega:
				if func(alpha) > num:
					return Result(alpha, func(alpha))
				if omega == alpha + 1:
					return Result(omega, func(omega))
				mid = (alpha + omega) // 2
				if func(mid) > num:
					omega = mid
				else:
					alpha = mid

	@staticmethod
	def less_than(num: int, func, size: int=1):
		if isinstance(func, list):
			index = bisect_left(func, num) - 1
			if index == -1:
				return Result(None, None)
			else:
				return Result(index, func[index])
		else:
			(alpha, omega) = (0, size - 1)
			if func(alpha) >= num:
				return Result(None, None)
			while alpha < omega:
				if func(omega) < num:
					return Result(omega, func(omega))
				if omega == alpha + 1:
					return Result(alpha, func(alpha))
				mid = (alpha + omega) // 2
				if func(mid) < num:
					alpha = mid
				else:
					omega = mid
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m, t1, t2, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if n <= k or m <= k:
	print(-1)
	quit()
bs = BinarySearch()
ans = 0
for i in range(min(n + 1, k + 1)):
	time = a[i] + t1
	index = bs.greater_than(time - 1, b).index
	if index is None:
		print(-1)
		quit()
	index += k - i
	if index >= m:
		print(-1)
		quit()
	ans = max(ans, b[index] + t2)
print(ans)


(n, m, x, y, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	a[i] += x
i = 0
j = 0
r = -1
while i < n and j < m:
	if b[j] >= a[i]:
		if k > 0:
			if k == m - j:
				break
			else:
				k += -1
				i += 1
		else:
			r = b[j] + y
			break
	j += 1
print(r)


import sys, math

def read_int():
	return int(sys.stdin.readline().strip())

def read_int_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def read_string():
	return sys.stdin.readline().strip()

def read_string_list(delim=' '):
	return sys.stdin.readline().strip().split(delim)
from bisect import bisect_left
(n, m, ta, tb, k) = read_int_list()
arr = read_int_list()
for i in range(n):
	arr[i] += ta
dep = read_int_list()
dep.append(float('inf'))
if k >= min(m, n) or arr[0] > dep[-1]:
	print(-1)
	sys.exit()
ans = -1
for i in range(0, k + 1):
	start_pos = min(i, n - 1)
	end_pos = min(bisect_left(dep, arr[start_pos]) + k - i, m)
	if dep[end_pos] == float('inf'):
		print(-1)
		sys.exit()
	ans = max(ans, dep[end_pos] + tb)
print(ans)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from collections import defaultdict as dd, Counter as C
from bisect import bisect_left as bl
(n, m, ta, tb, k) = I()
a = [i + ta for i in I()]
b = I() + [INF]
ans = -1
for i in range(min(n, k + 1)):
	time = a[i]
	r = k - i
	ok = bl(b, time)
	t = b[min(m, ok + r)]
	ans = max(ans, t + tb)
if k >= n or k >= m or ans >= INF:
	ans = -1
print(ans)


from sys import stdin
import bisect
input = stdin.readline
(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if k >= n:
	print(-1)
	exit()
ans = 0
try:
	for x in range(k + 1):
		arrive_b_time = a[x] + ta
		idx = bisect.bisect_left(b, arrive_b_time) + k - x
		ans = max(ans, b[idx] + tb)
	print(ans)
except:
	print(-1)


import bisect as bs
(n, m, ta, tb, k) = map(int, input().split())
it = list(map(int, input().split()))
it2 = list(map(int, input().split()))
ind = 0
can_b = 0
st = False
ma = 0
if k >= n or k >= m:
	print(-1)
else:
	for i in range(k + 1):
		x = it[i] + ta
		xx = bs.bisect_left(it2, x)
		xx += k - i
		if xx >= m:
			ma = -1
			break
		ans = it2[xx] + tb
		if ans > ma:
			ma = ans
	print(ma)


import sys
input = sys.stdin.readline
from bisect import *
(n, m, ta, tb, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if k >= n:
	print(-1)
	exit()
ans = 0
for i in range(k + 1):
	Bt = a[i] + ta
	idx = bisect_left(b, Bt)
	if idx + k - i >= m:
		print(-1)
		exit()
	ans = max(ans, b[idx + k - i] + tb)
print(ans)


import atexit
import io
import sys
import bisect
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())

def main():
	(n, m, ta, tb, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if n <= k or m <= k or bisect.bisect_left(a, b[-1] - ta) < k:
		res = -1
	else:
		ck = k
		res = -1
		for i in range(k + 1):
			j = bisect.bisect_left(b, a[i] + ta) + k - i
			if j < m:
				res = max(res, b[j] + tb)
			else:
				res = -1
				break
	print(res)
main()


def match(aa, ia, ta, bb, ib):
	if ia > len(aa) - 1:
		return -1
	if ib > len(bb) - 1:
		return -1
	for i in range(ib, len(bb)):
		if bb[i] >= aa[ia] + ta:
			return i
	return -1
(n, m, ta, tb, k) = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
ia = 0
ib = match(aa, ia, ta, bb, 0)
if k >= n or k >= m:
	print(-1)
	exit(0)
if ib == -1 or ib + k >= m:
	print(-1)
	exit(0)
r = bb[ib + k] + tb
while ia < k:
	ia += 1
	ib = match(aa, ia, ta, bb, ib)
	if ib == -1 or ib + k - ia >= m:
		print(-1)
		exit(0)
	else:
		r = max(r, bb[ib + k - ia] + tb)
print(r)


import bisect
(n, m, ta, tb, k) = input().split()
n = int(n)
m = int(m)
ta = int(ta)
tb = int(tb)
k = int(k)
if k >= m or k >= n:
	print(-1)
	exit()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
e = 0
flag = True
for i in range(k + 1):
	arriveAtB = a[i] + ta
	r = k - i
	d = bisect.bisect_right(b, arriveAtB)
	if b[d - 1] == arriveAtB:
		d -= 1
	if d + r >= len(b):
		flag = False
	else:
		e = max(b[d + r] + tb, e)
if flag:
	print(e)
else:
	print(-1)


t = list(map(int, input().split(' ')))
n = t[0]
m = t[1]
ta = t[2]
tb = t[3]
k = t[4]
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
b1 = []
j = 0
q = 0
for i in range(n):
	a[i] = a[i] + ta
	while j < m:
		if a[i] <= b[j]:
			q += 1
			b1.append(b[j])
			j += 1
			break
		j += 1
if q <= k:
	print(-1)
else:
	print(b1[k] + tb)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		(n, m, ta, tb, k) = ria()
		a = ria()
		b = ria()
		ans = 0
		for i in range(k + 1):
			nt = i
			mt = k - i
			if nt >= n or mt >= m:
				ans = -1
				break
			p = bisect.bisect_left(b, a[nt] + ta)
			if p + mt >= m:
				ans = -1
				break
			ans = max(ans, b[p + mt] + tb)
		print(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def prime_factors(x):
	s = set()
	n = x
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			s.add(i)
		i += 1
	if n > 1:
		s.add(n)
	return s
from collections import Counter
import heapq
from collections import Counter
from bisect import bisect_right
import heapq
import bisect
(n, m, t1, t2, k) = map(int, input().split())
arr = list(map(int, input().split()))
ls = list(map(int, input().split()))
if k >= n or k >= m:
	print('-1')
else:
	ans = 0
	j = 0
	for i in range(k + 1):
		while j < m and arr[i] + t1 > ls[j]:
			j += 1
		if j + k - i >= m:
			print(-1)
			exit()
		ans = max(ans, ls[j + k - i] + t2)
	print(ans)