n, m = map(int, input().split())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
t = 10
for q in range(n):
    for g in range(m):
        if a1[q] == a2[g]:
            if a1[q] < t:
                t = a1[q]
if t != 10:
    print(t)
    exit(0)
i = min(a1)
j = min(a2)
answ = min(i,j)*10 + max(i,j)
print(answ)