n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

min_a = min(a)
min_b = min(b)

res = 10

for i in a:
    if i in b and res > i:
        res = i
        
if res == 10:
    if min_b > min_a:
        res = min_a*10+min_b
    elif min_b < min_a:
        res = min_b*10+min_a
    else: res = min_a
print(res)