n, m = map(int, (input().split()))
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))

l3 = []
for item in l1:
    if item in l2:
        l3.append(item)

if len(l3) != 0:
    print(min(l3))
else:
    if min(l1) < min(l2):    
        print((min(l1)*10) + min(l2))
    else:
        print((min(l2)*10) + min(l1))