a = []
b = []
res = []
n, m = 0, 0
x, y = 0, 0
f = 0
n, m = map(int, input().split())
a = input().split()
b = input().split()
a = a[:n]
b = b[:m]
for i in range(n):
    a[i] = int(a[i])
for i in range(m):
    b[i] = int(b[i])
    
x = min(a)
y = min(b)

for i in range(n):
    if a[i] in b:
        res.append(a[i])
        f += 1

if f != 0:
    print(min(res))
else:
    print(x*10 + y)

