a = int(input())
max = 0
i = 1
while i <= a:
temp = int(input())
if max<temp and temp % 5 == 0:
max = temp
i = i + 1
print(max)
N = int(input())
_max = -1
for i in range(N):
x = int(input())
if (x % 5 == 0) and (x > _max):
_max = x
print(_max)