n, m = [int (x) for x in input().split()]
l1 = [int (x) for x in input().split()]
l2 = [int (x) for x in input().split()]

minl1 = min(l1)
minl2 = min(l2)

def printer(a,b):
    print(str(a)+str(b))

if(n == 1 and m == 1):
    if(minl1 == minl2):
        print(minl1)
    else:
        if(minl1>minl2):
            print(minl1, minl2)
        else:
            print(minl2+minl1)
elif(n == 1 and m > 1):
    if(minl1>minl2):
        print(minl1, minl2)
    else:
        print(minl2+minl1)
elif(n > 1 and m == 1):
    if(minl1>minl2):
        print(minl1, minl2)
    else:
        print(minl2+minl1)
else:
    if(minl1 == minl2):
        print(minl1)
    else:
        if(minl1>minl2):
            print(minl1, minl2)
        else:
            print(minl2+minl1)
