l1, l2 = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ak = [0 for i in range(10)]
bk = [0 for i in range(10)]
for el in a:
    ak[el] += 1
for el in b:
    bk[el] += 1
ans = 0
q = 0
for i in range(10):
    if ak[i] > 0 and bk[i] > 0:
        ans = i
        q = 1
        break
if q == 1:
    print(ans)
else:
    if min(a) == 0:
        sec_m = 10
        for j in range(1, 10):
            if ak[j] > 0:
                sec_m = j
                break
        print (min(min(sec_m, min(b)) * 10 + max(sec_m, min(b)), min(b) * 10))
    elif min(b) == 0:
        for j in range(1, 10):
            sec_m = 10
            if bk[j] > 0:
                sec_m = j
                break
        print (min(min(sec_m, min(a)) * 10 + max(sec_m, min(a)), min(a) * 10))    
    else:
        print(min(min(a), min(b)) * 10 + max(min(a), min(b)))
        
    