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

min_a = a[0]
min_b = b[0]

for i in range(1, n):
    if a[i] < min_a:
        min_a = a[i]

for i in range(1, m):
    if b[i] < min_b:
        min_b = b[i]

minimal = 0
if min_a < min_b:
    minimal = min_a * 10 + min_b
elif min_a == min_b:
    minimal = min_a
else:
    minimal = min_b * 10 + min_a

for i in range(n):
    for j in  range(m):
        if a[i] == b[j] and a[i]< minimal:
            minimal = a[i]

print(minimal)
