a = []
while True:
temp = int(input())
if temp != 0:
a.append(temp)
else:
break
if a != []:
print(max(a))
print(0)
a = []
while True:
temp = int(input())
if temp != 0:
a.append(temp)
else:
break
if a != []:
print(max(a))
else:
print(0)