n_m = input().split()
n, m = n_m

n, m = int(n), int(m)

l1 = input().split()
l2 = input().split()

l1 = [int(x) for x in l1]
l2 = [int(y) for y in l2]

menorl1 = 10
menorl2 = 10

i = 0
while i < n:
    if l1[i] < menorl1:
        menorl1 = l1[i]
    i += 1

j = 0
while j < m:
    if l2[j] < menorl2:
        menorl2 = l2[j]
    j += 1

coincid = 10
for e in l1:
    if e in l2:
        if e < coincid:
            coincid = e

if coincid == 10:
    menor = min(menorl1, menorl2)
    maior = max(menorl1, menorl2)
    print(str(menor) + str(maior))

else:
    print(coincid)