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

a.sort()
b.sort()

x = 0

for i in a:
    if i in b and x == 0:
        x = i

if x == 0:
    c = []
    c.append(a[0])
    c.append(b[0])
    c.sort()
    x = c[0] * 10 + c[1]

print(x)
