xz=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
min=a[0]
min1=b[0]
for i in range (len (a)):
    if min>a[i]:
        min=a[i]
for j in range (len(b)):
    if min1>b[j]:
        min1=b[j]
if min==min1:
    print (min)
else:
    print (min, min1)