#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define SIZE 100
#define MAX_VAL 100000000

int get_min(int num1, int num2){
    if(num1 >= num2) return num2;
    return num1;
}

int get_max(int num1, int num2){
    if(num1 >= num2) return num1;
    return num2;
}

int main(){
    int trial;
    scanf("%d", &trial);
    for(int i = 0; i < trial; i++){
        int n, range;
        int arr[SIZE];
        scanf("%d %d", &n, &range);
        for(int j = 0; j < n; j++)
            scanf("%d", &arr[j]);

        bool check = true;
        int max = MAX_VAL + 1, min = 0;
        int temp_max, temp_min;
        for(int j = 0; j < n - 1; j++){
            if(arr[j] + range >= arr[j + 1] - range){
                temp_min = arr[j + 1] - range;
                temp_max = arr[j] + range;
                if(min <= max){
                    min = get_max(temp_min, min);
                    max = get_min(temp_max, max);
                }
                else{
                    check = false;
                    printf("-1\n");
                    break;
                }
            }
            else{
                printf("-1\n");
                check = false;
                break;
            }
        }
        if(check) printf("%d\n", max);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define SIZE 100
#define MAX_VAL 200000000

int compare(const void *a, const void *b){
    int num1 = *(int *)a;
    int num2 = *(int *)b;

    if(num1 < num2) return -1;
    if(num1 > num2) return 1;
    return 0;
}

int get_min(int num1, int num2){
    if(num1 >= num2) return num2;
    return num1;
}

int get_max(int num1, int num2){
    if(num1 >= num2) return num1;
    return num2;
}

int main(){
    int trial;
    scanf("%d", &trial);
    for(int i = 0; i < trial; i++){
        int n, range;
        int arr[SIZE];
        scanf("%d %d", &n, &range);
        for(int j = 0; j < n; j++)
            scanf("%d", &arr[j]);

        qsort(arr, n, sizeof(int), compare);

        bool flag = true;
        int max = MAX_VAL + 1, min = 0;
        int temp_max, temp_min;

        for(int j = 0; j < n; j++){
            if(j < n - 1 && arr[j] + range >= arr[j + 1] - range){
                temp_min = arr[j + 1] - range;
                temp_max = arr[j] + range;
                min = get_max(temp_min, min);
                max = get_min(temp_max, max);
            }
            if(arr[j] + range < arr[j + 1] - range){
                flag = false;
                break;
            }
        }
        if(flag && max > 0) printf("%d\n", max);
        else printf("-1\n");
    }
    return 0;
}


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):
        """Searches for smallest element greater than num!"""
        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):
        """Searches for largest element less than num!"""
        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)


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):
        """Searches for smallest element greater than num!"""
        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):
        """Searches for largest element less than num!"""
        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
    index += (k - i)
    if index >= m:
        print(-1)
        quit()
    ans = max(ans, b[index] + t2)

print(ans)


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):
        """Searches for smallest element greater than num!"""
        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):
        """Searches for largest element less than num!"""
        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 not index:
        print(-1)
        quit()
    index += (k - i)
    if index >= m:
        print(-1)
        quit()
    ans = max(ans, b[index] + t2)

print(ans)


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):
            #print(ind,k,i,ind-1+(k-i))
            if(mx<lbb[ind-1+(k-i)]):
                mx=lbb[ind-1+(k-i)]
        elif(ind+(k-i))>=m and a!=lb[-1]:
            lol=1
            #print("lol",a,ind)
            break
        elif(ind+(k-i))>=m and a==lb[-1]:
            if(mx<lbb[-1]):
                mx=lbb[-1]
        else:
            if(mx<lbb[ind+(k-i)]):
                mx=lbb[ind+(k-i)]
if(lol==1):
    print(-1)
else:
    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()]

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


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
    if j>=n:
        break
print(ans)


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()))
b=list(map(int, input().split()))
j=0
ans=-1
for i in range(m):
    if a[j]+ta<=b[i]:
        k-=1
        j+=1
    if k<0:
        ans=b[i]+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)


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)
pre = float('inf')
for i in t1:
    pos = bisect_left(t2, i + ta)
    if pos > pre:
        k -= 1
        if k == 0:
            break
    pre = pos

print(t2[pos + k] + tb)


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)
pre = float('inf')
for i in t1:
    pos = bisect_left(t2, i + ta)
    if pos > pre:
        k -= 1
        if k == 0:
            break

    pre = pos

print(-1) if pos + k >= m else print(t2[pos + k] + tb)


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)


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)
pre = float('inf')
cnt = 1
res = 0
for i in t1:
    pos = bisect_left(t2, i + ta)
    if pos == pre:
        cnt += 1
        continue
    elif pos > pre:
        if pos == m:
            if pre + k >= m:
                res = -1
            else:
                res = t2[pre + k] + tb
            print(res)
            exit(0)
        else:
            gap = pos - pre
            to_erase = min(gap, cnt)
            if k < to_erase:
                print(t2[pre + k] + tb)
                exit(0)
            else:
                k -= to_erase
                pre = pos
                cnt = 1
    else:
        pre = pos

print(-1) if pre + k >= m else print(t2[pre + k] + tb)


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)
pre = float('inf')
cnt = 1
res = 0
for i in t1:
    if k <= 0 or pre == m:
        break
    pos = bisect_left(t2, i + ta)
    if pos == pre:
        cnt += 1
        continue
    elif pos > pre:
        # if pos == m:
        #     if pre + k >= m:
        #         res = -1
        #     else:
        #         res = t2[pre + k] + tb
        #     print(res)
        #     exit(0)
        # else:
        gap = pos - pre
        to_erase = min(gap, cnt)
        if k < to_erase:
            print(t2[pre + k] + tb)
            exit(0)
        else:
            k -= to_erase
            pre = pos
            cnt = 1
    else:
        pre = pos

print(-1) if pre + k >= m else print(t2[pre + k] + tb)


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
# c=sorted((i,int(val))for i,val in enumerate(input().split()))
import heapq
# c=sorted((i,int(val))for i,val in enumerate(input().split()))
# n = int(input())
# ls = list(map(int, input().split()))
# n, k = map(int, input().split())
# n =int(input())
#arr=[(i,x) for i,x in enum]
#arr.sort(key=lambda x:x[0])
#print(arr)
#import math
# e=list(map(int, input().split()))
from collections import Counter
#print("\n".join(ls))
#print(os.path.commonprefix(ls[0:2]))
#n=int(input())
from bisect import  bisect_right
#d=sorted(d,key=lambda x:(len(d[x]),-x))  d=dictionary     d={x:set() for x in arr}
#n=int(input())
#n,m,k= map(int, input().split())
import heapq
#for _ in range(int(input())):
#n,k=map(int, input().split())
#input=sys.stdin.buffer.readline
#for _ in range(int(input())):
#n=int(input())
n,m,t1,t2,k = map(int, input().split())
arr = list(map(int, input().split()))
ls= list(map(int, input().split()))
tt=k
i=0
j=0
ans=-1
while i<n and  j<m:

    while   j<m and arr[i]+t1>ls[j]:
        j+=1
    if k>0:
        if i+1<n and j<m  and  arr[i+1]+t1<=ls[j]:
            j+=1
        else:
            i+=1
        k-=1
    else:
        ans=ls[j]
        break

if ans==-1 or n<=tt or m<=tt:
    print(-1)
else:
    print(ans+t2)

import bisect


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
# c=sorted((i,int(val))for i,val in enumerate(input().split()))
import heapq
# c=sorted((i,int(val))for i,val in enumerate(input().split()))
# n = int(input())
# ls = list(map(int, input().split()))
# n, k = map(int, input().split())
# n =int(input())
#arr=[(i,x) for i,x in enum]
#arr.sort(key=lambda x:x[0])
#print(arr)
#import math
# e=list(map(int, input().split()))
from collections import Counter
#print("\n".join(ls))
#print(os.path.commonprefix(ls[0:2]))
#n=int(input())
from bisect import  bisect_right
#d=sorted(d,key=lambda x:(len(d[x]),-x))  d=dictionary     d={x:set() for x in arr}
#n=int(input())
#n,m,k= map(int, input().split())
import heapq
#for _ in range(int(input())):
#n,k=map(int, input().split())
#input=sys.stdin.buffer.readline
#for _ in range(int(input())):
#n=int(input())
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)


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
# c=sorted((i,int(val))for i,val in enumerate(input().split()))
import heapq
# c=sorted((i,int(val))for i,val in enumerate(input().split()))
# n = int(input())
# ls = list(map(int, input().split()))
# n, k = map(int, input().split())
# n =int(input())
#arr=[(i,x) for i,x in enum]
#arr.sort(key=lambda x:x[0])
#print(arr)
#import math
# e=list(map(int, input().split()))
from collections import Counter
#print("\n".join(ls))
#print(os.path.commonprefix(ls[0:2]))
#n=int(input())
from bisect import  bisect_right
#d=sorted(d,key=lambda x:(len(d[x]),-x))  d=dictionary     d={x:set() for x in arr}
#n=int(input())
#n,m,k= map(int, input().split())
import heapq
#for _ in range(int(input())):
#n,k=map(int, input().split())
#input=sys.stdin.buffer.readline
#for _ in range(int(input())):
#n=int(input())
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
    for x in range(k):
        t=arr[x+1]

        var=bisect.bisect_right(ls,t+t1)
        var+=(k-x)

        ans=max(ans,ls[min(var,m-1)]+t2)
    print(ans)


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
# c=sorted((i,int(val))for i,val in enumerate(input().split()))
import heapq
# c=sorted((i,int(val))for i,val in enumerate(input().split()))
# n = int(input())
# ls = list(map(int, input().split()))
# n, k = map(int, input().split())
# n =int(input())
#arr=[(i,x) for i,x in enum]
#arr.sort(key=lambda x:x[0])
#print(arr)
#import math
# e=list(map(int, input().split()))
from collections import Counter
#print("\n".join(ls))
#print(os.path.commonprefix(ls[0:2]))
#n=int(input())
from bisect import  bisect_right
#d=sorted(d,key=lambda x:(len(d[x]),-x))  d=dictionary     d={x:set() for x in arr}
#n=int(input())
#n,m,k= map(int, input().split())
import heapq
#for _ in range(int(input())):
#n,k=map(int, input().split())
#input=sys.stdin.buffer.readline
#for _ in range(int(input())):
#n=int(input())
n,m,t1,t2,k = map(int, input().split())
arr = list(map(int, input().split()))
ls= list(map(int, input().split()))
i=0
j=0
ans=-1
while i<n and  j<m:

    while   j<m and arr[i]+t1>ls[j]:
        j+=1
    if k>0:
        if i+1<n and j<m  and  arr[i+1]+t1<=ls[j]:
            j+=1
        else:
            i+=1
        k-=1
    else:
        ans=ls[j]
        break
if ans==-1:
    print(-1)
else:
    print(ans+t2)

import bisect


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
# c=sorted((i,int(val))for i,val in enumerate(input().split()))
import heapq
# c=sorted((i,int(val))for i,val in enumerate(input().split()))
# n = int(input())
# ls = list(map(int, input().split()))
# n, k = map(int, input().split())
# n =int(input())
#arr=[(i,x) for i,x in enum]
#arr.sort(key=lambda x:x[0])
#print(arr)
#import math
# e=list(map(int, input().split()))
from collections import Counter
#print("\n".join(ls))
#print(os.path.commonprefix(ls[0:2]))
#n=int(input())
from bisect import  bisect_right
#d=sorted(d,key=lambda x:(len(d[x]),-x))  d=dictionary     d={x:set() for x in arr}
#n=int(input())
#n,m,k= map(int, input().split())
import heapq
#for _ in range(int(input())):
#n,k=map(int, input().split())
#input=sys.stdin.buffer.readline
#for _ in range(int(input())):
#n=int(input())
n,m,t1,t2,k = map(int, input().split())
arr = list(map(int, input().split()))
ls= list(map(int, input().split()))
i=0
j=0
ans=-1
while i<n and  j<m:

    while   j<m and arr[i]+t1>ls[j]:
        j+=1
    if k>0:
        if i+1<n and  arr[i+1]+t1<=ls[j]:
            j+=1
        else:
            i+=1
        k-=1
    else:
        ans=ls[j]
        break
if ans==-1:
    print(-1)
else:
    print(ans+t2)


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(1e9)+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)


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(1e9)+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:]

ans = -inf
b.append(inf)
for i in range(n):
	if i > k:
		break
	else:
	    j = bisect_left(b, a[i])
	    ans = max(ans, b[min(len(b),  j+k-i)])

print(ans+tb if abs(ans)!= inf else -1)


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(1e9)+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),  j+k-i)])

	print(ans+tb if abs(ans)!= inf else -1)

else:
	print(-1)


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(1e9)+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)
	for i in range(n):
		if i > k:
			break
		else:
		    j = bisect_left(b, a[i])
		    ans = max(ans, b[min(len(b),  j+k-i)])

	print(ans+tb if abs(ans)!= inf else -1)

else:
	print(-1)


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

if __name__=="__main__":
    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):
            idx=bisect.bisect_left(b,B[i])
            if idx<m:
                if k-i>0:
                    i2=idx+(k-i)
                else:
                    i2=idx
                #print(idx,i2)
                if mx<b[i2]:
                    mx=b[i2]

        print(mx+tb)


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

if __name__=="__main__":
    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]
        #print(B)
        mx=-1
        for i in range(n):
            idx=bisect.bisect_left(b,B[i])
            if idx<m:
                if k-i>0:
                    i2=idx+(k-i)
                else:
                    i2=idx
                #print(idx,i2)
                if mx<b[i2]:
                    mx=b[i2]
        if mx!=-1:
            print(mx+tb)
        else:
            print(-1)


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

if __name__=="__main__":
    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]
        #print(B)
        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)
                    #print(idx,i2)
                    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)


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

if __name__=="__main__":
    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]
        #print(B)
        mx=-1
        for i in range(n):
            idx=bisect.bisect_left(b,B[i])
            if idx<m:
                if k-i>=0:
                    i2=idx+(k-i)
                else:
                    break
                #print(idx,i2)
                if i2<m:
                    if mx<b[i2]:
                        mx=b[i2]

        if mx!=-1:
            print(mx+tb)
        else:
            print(-1)


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

if __name__=="__main__":
    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]
        #print(B)
        mx=-1
        for i in range(n):
            idx=bisect.bisect_left(b,B[i])
            if idx<m:
                if k-i>=0:
                    i2=idx+(k-i)
                else:
                    break
                #print(idx,i2)
                if mx<b[i2]:
                    mx=b[i2]
        if mx!=-1:
            print(mx+tb)
        else:
            print(-1)


#------------------------------warmup----------------------------
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")

#-------------------game starts now-----------------------------------------------------
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()))
for i in range(k+1):
    ind=countGreater(l1,m,l[i]+ta)
    #print(ind)
    ind=m-ind
    ind+=(k-i)
    #print(ind,"i")
    if ind>=m:
        print(-1)
        sys.exit()
    else:
        ans=max(ans,l1[ind]+tb)
print(ans)


#------------------------------warmup----------------------------
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")

#-------------------game starts now-----------------------------------------------------
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)
    #print(ind)
    ind=m-ind
    ind+=(k-i)
    #print(ind,"i")
    if ind>=m:
        print(-1)
        sys.exit()
    else:
        ans=max(ans,l1[ind]+tb)
print(ans)


"""
    Satwik_Tiwari ;) .
    20 june , 2020  - Tuesday
"""

#===============================================================================================
#importing some useful libraries.
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  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

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):
    """Prints the values to a stream, or to sys.stdout by default."""
    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)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
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")  #as stdout.write always print sring.
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) : # Check Prime Number or not
    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

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(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): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    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 #special left case
    return (a)

def solve():
    n,m,ta,tb,k = sep()
    a= lis()
    b = lis()

    if(k >= n or a[k] > b[m-1]):
        print(-1)
        return

    newtime = []
    for i in range(0,n):
        newtime.append([a[i]+ta,k-i])
    # print(newtime)

    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):
            ans = max(ans,b[m-1]+tb)
        else:
            ans = max(ans,b[ind+newtime[i][1]] + tb)
    print(ans)

testcase(1)
# testcase(int(inp()))


"""
    Satwik_Tiwari ;) .
    20 june , 2020  - Tuesday
"""

#===============================================================================================
#importing some useful libraries.
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  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

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):
    """Prints the values to a stream, or to sys.stdout by default."""
    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)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
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")  #as stdout.write always print sring.
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) : # Check Prime Number or not
    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

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(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): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    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 #special left case
    return (a)

def solve():
    n,m,ta,tb,k = sep()
    a= lis()
    b = lis()

    if(k >= n or a[k]+ta > b[m-1]):
        print(-1)
        return

    newtime = []
    for i in range(0,n):
        newtime.append([a[i]+ta,k-i])
    # print(newtime)

    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):
            ans = max(ans,b[m-1]+tb)
        else:
            ans = max(ans,b[ind+newtime[i][1]] + tb)
    print(ans)

testcase(1)
# testcase(int(inp()))


"""
    Satwik_Tiwari ;) .
    20 june , 2020  - Tuesday
"""

#===============================================================================================
#importing some useful libraries.
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  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

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):
    """Prints the values to a stream, or to sys.stdout by default."""
    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)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
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")  #as stdout.write always print sring.
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) : # Check Prime Number or not
    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

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(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): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    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 #special left case
    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])
    # print(newtime)

    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)
# testcase(int(inp()))


"""
    Satwik_Tiwari ;) .
    20 june , 2020  - Tuesday
"""

#===============================================================================================
#importing some useful libraries.
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  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

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):
    """Prints the values to a stream, or to sys.stdout by default."""
    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)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
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")  #as stdout.write always print sring.
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) : # Check Prime Number or not
    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

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(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): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    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 #special left case
    return (a)

def solve():
    n,m,ta,tb,k = sep()
    a= lis()
    b = lis()

    if(k >= n or a[k] > b[m-1]):
        print(-1)
        return

    newtime = []
    for i in range(0,n):
        newtime.append([a[i]+ta,k-i])
    # print(newtime)

    ans = 0
    for i in range(0,len(newtime)):
        if(newtime[i][1] <0):
            break
        ind = bs(b,0,len(b),newtime[i][0])
        ans = max(ans,b[ind+newtime[i][1]] + tb)
    print(ans)

testcase(1)
# testcase(int(inp()))


"""
    Satwik_Tiwari ;) .
    20 june , 2020  - Tuesday
"""

#===============================================================================================
#importing some useful libraries.
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  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

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):
    """Prints the values to a stream, or to sys.stdout by default."""
    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)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
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")  #as stdout.write always print sring.
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) : # Check Prime Number or not
    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

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(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): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    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 #special left case
    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])
    # print(newtime)

    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):
            ans = max(ans,b[m-1]+tb)
        else:
            ans = max(ans,b[ind+newtime[i][1]] + tb)
    print(ans)

testcase(1)
# testcase(int(inp()))


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)
    tmp = bnums[insert + k - i] + b
    if ans < tmp:
        ans = tmp
print(ans)
#
# while(maxpos - minpos > 1):
#     mid = (minpos + maxpos) // 2
#     judge(anums, bnums, k, mid)


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 == m:
        print(-1)
        sys.exit()
    tmp = bnums[insert + k - i] + b
    if ans < tmp:
        ans = tmp
print(ans)
#
# while(maxpos - minpos > 1):
#     mid = (minpos + maxpos) // 2
#     judge(anums, bnums, k, mid)


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)
#
# while(maxpos - minpos > 1):
#     mid = (minpos + maxpos) // 2
#     judge(anums, bnums, k, mid)


from bisect import *

n, m, ta, tb, k = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

a = [c + ta for c in a]

ans = 0

if k >= min(n, m):
	print(-1)

else:

	for i in range(k + 1):

		t = bisect_left(b, a[i])

		if t + k < m + i:
			ans = max(ans, b[t + k - i] + tb)
		else:
			ans = -1
			break

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

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)


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


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)


n,m,ta,tb,k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
gone = 0
# print(a)
# print(b)
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):
            break
        flight_b = b[j]
        # print(gone,i,j,flight_a,flight_b)
        max_t = max(max_t, flight_b+tb)
    print(max_t)


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


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


n,m,ta,tb,k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
gone = 0
# print(a)
# print(b)
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):
            continue
        flight_b = b[j]
        # print(gone,i,j,flight_a,flight_b)
        max_t = max(max_t, flight_b+tb)
    print(max_t)


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


n,m,ta,tb,k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
gone = 0
# print(a)
# print(b)
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]
        # print(gone,i,j,flight_a,flight_b)
        max_t = max(max_t, flight_b+tb)
    print(max_t)


n,m,ta,tb,k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# print(a)
# print(b)
max_t = -1
if k >= n:
    print(-1)
else:
    for i in range(k, -1, -1):
        flight_a = a[i]
        l = 0
        r = m-1
        while r - l > 1:
            mid = l + (r-l)//2
            if(b[mid] < flight_a+ta):
                l = mid
            else:
                r = mid
        j = r + k - i
        if(j >= m or flight_a+ta > b[j]):
            continue
        flight_b = b[j]
        # print(r,i,j,flight_a,flight_b)
        max_t = max(max_t, flight_b+tb)
    print(max_t)


n,m,ta,tb,k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# print(a)
# print(b)
max_t = -1
if k >= n:
    print(-1)
else:
    for i in range(k, -1, -1):
        flight_a = a[i]
        l = 0
        r = m-1
        while r - l > 1:
            mid = l + (r-l)//2
            if(b[mid] < flight_a+ta):
                l = mid
            else:
                r = mid
        j = r + k - i
        if(j >= m):
            continue
        # print(r,k,i,j)
        flight_b = b[j]
        max_t = max(max_t, flight_b+tb)
    print(max_t)


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


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
    elif a[i] - b[j] > 0:
        j += 1
    else:
        j += 1
        k -= 1
if k != 0:
    print(-1)
    print(i, j)
else:
    print(b[bisect.bisect_left(b, a[i] + ta, j + 1) - 1] + tb)


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()))
i = j = 0
while i < n and j < m and k:
    if a[i] - b[j] == 0:
        i += 1
        j += 1
        k -= 1
    elif a[i] - b[j] > 0:
        j += 1
    else:
        j += 1
        k -= 1
if k != 0 or j == m:
    print(-1)
else:
    print(b[bisect.bisect_left(b, a[i] + ta, j + 1) - 1] + tb)


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
    elif a[i] - b[j] > 0:
        j += 1
    else:
        j += 1
        if i < n - 1:
            if a[i + 1] > b[i]:
                i += 1
        k -= 1
if k != 0 or j == m:
    print(-1)
else:
    if a[i] > max(b[j:]):
        print(-1)
    else:
        print(b[bisect.bisect_left(b, a[i], j)] + tb)


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
    elif a[i] - b[j] > 0:
        j += 1
    else:
        j += 1
        k -= 1
if k != 0:
    print(-1)
else:
    print(b[bisect.bisect_left(b, a[i], j)] + tb)


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)
else:
    if a[i] > max(b[j:]):
        print(-1)
    else:
        print(b[bisect.bisect_left(b, a[i], j)] + tb)


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
    elif a[i] - b[j] > 0:
        j += 1
    else:
        j += 1
        k -= 1
if k != 0:
    print(-1)
else:
    print(b[bisect.bisect_left(b, a[i] + ta, j + 1) - 1] + tb)


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
        if n - i <= k or m - j <= k:
            break
    elif a[i] - b[j] > 0:
        j += 1
        if m - j <= k:
            break
    else:
        j += 1
        if i < n - 1:
            if a[i + 1] > b[i]:
                i += 1
        k -= 1
        if n - i <= k or m - j <= k:
            break
if k != 0 or j == m:
    print(-1)
else:
    if a[i] > max(b[j:]):
        print(a[i])
        print(-1)
    else:
        print(b[bisect.bisect_left(b, a[i], j)] + tb)


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
    elif a[i] - b[j] > 0:
        j += 1
    else:
        if i < n - 1:
            if a[i] > b[i]:
                i += 1
        j += 1
        k -= 1
if k != 0 or j == m or i == n:
    print(-1)
else:
    print(b[bisect.bisect_left(b, a[i], j)] + tb)


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
    elif a[i] - b[j] > 0:
        j += 1
    else:
        if i < n - 1:
            if a[i] > b[i]:
                i += 1
        j += 1
        k -= 1
if k != 0 or j == m:
    print(-1)
else:
    if a[i] > max(b[i:]):
        print(-1)
    else:
        print(b[bisect.bisect_left(b, a[i], j)] + tb)


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
    elif a[i] - b[j] > 0:
        j += 1
    else:
        if a[i] > b[i]:
            i += 1
        j += 1
        k -= 1
if k != 0 or j == m or i == n:
    print(-1)
else:
    if min(a[i:]) > min(b[j:]):
        print(-1)
    else:
        print(b[bisect.bisect_left(b, a[i], j)] + tb)


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()))
i = j = 0
while i < n and j < m and k:
    if a[i] - b[j] <= 0:
        i += 1
        k -= 1
    j += 1
if k != 0 or i == n or j == m:
    print(-1)
else:
    if a[i] > max(b[j:]):
        print(-1)
    else:
        print(b[j] + tb)


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
    elif a[i] - b[j] > 0:
        j += 1
    else:
        if a[i] > b[i]:
            i += 1
        j += 1
        k -= 1
if k != 0 or j == m or i == n:
    print(-1)
else:
    if min(a[i:]) > max(b[j:]):
        print(-1)
    else:
        print(b[bisect.bisect_left(b, a[i], j)] + tb)


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()))
i = j = 0
while i < n and j < m and k:
    if a[i] - b[j] <= 0:
        i += 1
        k -= 1
    j += 1
if k != 0:
    print(-1)
else:
    if a[i] > max(b[j:]):
        print(-1)
    else:
        print(b[bisect.bisect_left(b, a[i], j)] + tb)


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
    elif a[i] - b[j] > 0:
        j += 1
    else:
        if i < n - 1:
            if a[i + 1] > b[j]:
                i += 1
        j += 1
        k -= 1
if k != 0 or j == m:
    print(-1)
else:
    if a[i] > max(b[j:]):
        print(a[i])
        print(-1)
    else:
        print(b[bisect.bisect_left(b, a[i], j)] + tb)


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
    elif a[i] - b[j] > 0:
        j += 1
    else:
        j += 1
        k -= 1
if k != 0:
    print(-1)
else:
    print(b[bisect.bisect_right(b, a[i], j)] + tb)


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()))
i = j = 0
while i < n and j < m and k:
    if a[i] - b[j] <= 0:
        i += 1
        k -= 1
    j += 1
if k != 0 or i == n or j == m:
    print(-1)
else:
    if a[i] > max(b[j:]):
        print(-1)
    else:
        print(b[bisect.bisect_left(b, a[i], j)] + tb)


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
    elif a[i] - b[j] > 0:
        j += 1
    else:
        j += 1
        if i < n - 1:
            if a[i + 1] > b[j]:
                i += 1
        k -= 1
if k != 0 or j == m:
    print(-1)
else:
    if a[i] > max(b[j:]):
        print(a[i])
        print(-1)
    else:
        print(b[bisect.bisect_left(b, a[i], j)] + tb)


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
    elif a[i] - b[j] > 0:
        j += 1
    else:
        if i < n - 1:
            if a[i] > b[i]:
                i += 1
        j += 1
        k -= 1
if k != 0 or j == m or i == n:
    print(-1)
else:
    if ta == 277051245 and tb == 563497108:
        print(i, j, k)
    print(b[bisect.bisect_left(b, a[i], j)] + tb)


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
    elif a[i] - b[j] > 0:
        j += 1
        i += 1
    else:
        if i < n - 1:
            if a[i + 1] > b[j]:
                i += 1
        j += 1
        k -= 1
if k != 0 or j == m or i == n:
    print(-1)
else:
    if a[i] > max(b[j:]):
        print(a[i])
        print(-1)
    else:
        print(b[bisect.bisect_left(b, a[i], j)] + tb)


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
    elif a[i] - b[j] > 0:
        j += 1
    else:
        i += 1
        j += 1
        k -= 1
if k != 0 or j == m or i == n:
    print(-1)
else:
    print(b[bisect.bisect_left(b, a[i], j)] + tb)


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
    elif a[i] - b[j] > 0:
        j += 1
    else:
        if i < n - 1:
            if a[i] > b[i]:
                i += 1
        j += 1
        k -= 1
if k != 0 or j == m:
    print(-1)
else:
    if a[i] > max(b[j:]):
        print(a[i])
        print(-1)
    else:
        print(b[bisect.bisect_left(b, a[i], j)] + tb)


#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

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 >= min(n, m):
        print(-1)
    else:
        i = 0
        for j in range(m):
            if i < n and a[i] + ta <= b[j]:
                i += 1
                k -= 1
                if k < 0:
                    print(b[j] + tb)
                    exit(0)

# region fastio

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

# endregion

if __name__ == "__main__":
    main()


#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

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 >= min(n, m):
        print(-1)
    else:
        ans = - 1
        i = 0
        for j in range(m):
            if i < n and a[i] + ta <= b[j]:
                i += 1
                k -= 1
                if k < 0:
                    ans = b[j] + tb
                    break
        print(ans)

# region fastio

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

# endregion

if __name__ == "__main__":
    main()


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)

###### Author : Samir Vyas #######
###### Write Code Below    #######
def calc(f,s):
	global arr,dep,m,n
	if s >= m:
		return float("inf")

	while s < m and dep[s] < arr[f]:
		s += 1

	if s>=m:
		return float("inf")

	return dep[s]

n,m,ta,tb,k = read_int_list()
arr = read_int_list()

for i in range(n):
	arr[i] += ta

dep = read_int_list()

#chop
if k >= min(m,n) or arr[0] > dep[-1]:
	print(-1)
	sys.exit()

def increment_second(f,s):
	global arr,dep,m,n
	while s < m and dep[s] < arr[f]:
		s += 1
	return s

first = 0
second = increment_second(first,0)

for i in range(k):
	if first >= n or second >= m:
		break

	#cancel arriving flight
	if calc(first+1, second) > calc(first, second+1) :
		first += 1
		second = increment_second(first, second)
	else:
		second += 1

if first >= n or second >= m:
	print(-1)
	sys.exit()

print(calc(first, second)+tb)