a, b = map(int, input().split())

s_1 = input().split()
s_2 = input().split()

list_1 = [int(a) for a in s_1]
list_2 = [int(b) for b in s_2]

i, j = 0, 0
value_1 = 0
value_2 = 0

while len(list_1) - i > 0:
    if i == 0:
        value_1 = list_1[i]
    elif list_1[i] < value_1:
        value_1 = list_1[i]
    i += 1

while len(list_2) - j > 0:
    if j == 0:
        value_2 = list_2[j]
    elif list_2[j] < value_2:
        value_2 = list_2[j]
    j += 1

i, j = 0, 0
cond = []

while len(list_1) - i > 0:
    while len(list_2) - j > 0:
        if list_1[i] == list_2[j]:
            cond.append(list_1[i])
        j += 1
    j = 0
    i += 1


if value_1 == value_2:
    print(value_1)
elif len(cond) != 0:
    print(min(cond))
elif value_1 > value_2:
    print(value_2 * 10 + value_1)
else:
    print(value_1 * 10 + value_2)

