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)

if(minl1 < minl2):
    print(str(minl1)+str(minl2))
elif(minl1 > minl2):
    print(str(minl2)+str(minl1))
else:
    print(str(minl1))
