n, m = map(int, input().split())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a1z, a2z, z = 10, 10, 10
for i in a1:
    if i in a2:
        z = min(i, z)
    a1z = min(i, a1z)
for i in a2:
    a2z = min(a2z, i)
if z == 10:
    print(min(10 * a1z + a2z, 10 * a2z + a1z))
else:
    print(z)
