n, m = map(int, input().split())

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

go = False
num = []
for i in range(n):
    for j in range(m):
        if a[i] == b[j]:
            go = True
            num.append(a[i])

min1 = 99
min2 = 99
min3 = 99
if go:
    for i in num:
        if i < min3:
            min3 = i
    print(min3)
else:
    for i in range(n):
        if a[i] < min1:
            min1 = a[i]
    for i in range(m):
        if b[i] < min2:
            min2 = b[i]

    if min1 < min2:
        print(min1, min2, sep="")
    else:
        print(min2, min1, sep="")