if __name__ == '__main__':
n = int(input())
arr = map(int, input().split())
arr = list(arr)
x = max(arr)
y = -9999999
for i in range(0,n):
if arr[i]<x and arr[i] > y:
y = arr[i]
print(y)
n = int(input())
arr = list(map(int, input().split()))
zes = max(arr)
i=0
while(i<n):
if zes ==max(arr):
arr.remove(max(arr))
i+=1
print(max(arr))
#note: do not use set() will not work for negative numbers
# contact me : [email protected]