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: interview

Starter code:

Solutions:
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())



from bisect import bisect_left as bl
n, m, t1, t2, k = list(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)


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 = b[-1] + tb # last flight
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)


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)


from bisect import bisect_left
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:
    print(-1)
    return

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)
        return

    ma = max(ma, b[j + q] + tb)

print(ma)


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) # cancel all
        return
    if bisect_left(b, a[0] + ta) == len(b):
        print(-1) # no flight from B to C
        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) # no flight from B to C
            return
        arrival = b[bisect_left(b, a[i] + ta) + (k - i)] + tb
        if arrival > latest_arrival:
            latest_arrival = arrival
    print(latest_arrival)

def __starting_point():
    main()

__starting_point()

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)

n,m,ta,tb,k=list(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)
    
        


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)
    # print(t, b[j])
    if j is None:
        print(-1)
        raise SystemExit(0)
    # print('Cancel ', k - i)
    j += k - i
    if j >= len(b):
        print(-1)
        raise SystemExit(0)
    # print('b[j]', b[j])
    # print(b[j] + tb)
    ans = max(ans, b[j] + tb)
print(ans)


import sys
from bisect import bisect_left
# gcd
# from fractions import gcd
# from math import ceil, floor
# from copy import deepcopy
# from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# fin = open('in_1.txt', 'r')
# sys.stdin = fin
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())
# template


def __starting_point():

    # write code
    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()
    # print(a)
    ans = -10**9
    for i in range(k+1):
        # print(b[bisect_left(b, a[i]) + (k - i)])
        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()

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
from bisect import bisect_left as bl
n,m,ta,tb,k=list(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)
    
    




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)

# alpha = "abcdefghijklmnopqrstuvwxyz"
# prime = 998244353 
INF = 100_000_000

# from heapq import heappush, heappop
# from collections import defaultdict
# from math import sqrt
# from collections import deque

t = 1#int(input())

for test in range(t):
    # n = int(input())
    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)

    


n, m, ta, tb, k = list(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
        #print(i, num)
        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()))

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)




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)


import bisect
import sys
input = sys.stdin.readline
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]

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)


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 = 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)


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)<=0 or (m-k) <= 0:
	print(-1)
else:
	if 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)



n,m,ta,tb,k = list(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)
            return
        fb_time= fb[j]
    k-=1
    i+=1
    if i>=n:
        print(-1)
        return
    j+=1
    if j >= m:
        print(-1)
        return
fb_time=arrival[i]
for k in range(j,m):
    if fb_time<=fb[k]:
        idex= k;
        print(fb[k]+tb)
        return
print(-1)






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()
	# print(*a)
	# print(*b)
	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)

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:
		# all flights in a will be cancelled
		print(-1)
		return
	else:
		# dk flights from a has been cancelled
		key = a[dk]
		dk = k-_k
		while j<m and b[j]<key:
			j+=1
		# print("j", j)
		if j is m:
			print(-1)
			return
		else:
			if m<=dk+j:
				print(-1)
				return
			else:
				ans = max(ans, b[j+dk]+tb)
	# print("k {} | {} | {}".format(_k, a[dk+1], b[j+dk]))

print(ans)

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)