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

l1 = map(int, raw_input().split())
l2 = map(int, raw_input().split())
nums = []

for i in range(n):
    if l1[i] in l2:
        nums.append(l1[i])
    for j in range(m):
        aux = int(str(l1[i]) + str(l2[j]))
        nums.append(aux)

print min(nums)