b, c = map(int, raw_input().split())

linha1 = map(int, raw_input().split())
linha2 = map(int, raw_input().split())
numeros = []

for i in range(b):
    if linha1[i] in linha2:
        numeros.append(linha1[i])
    for x in range(c):
        auxiliar = int(str(linha1[i]) + str(linha2[x]))
        numeros.append(auxiliar)
        auxiliar = int(str(linha2[x]) + str(linha1[i]))
        numeros.append(auxiliar)

print min(numeros)