size1, size2 = map(int, raw_input().split())


lista1 = map(int,raw_input().split())
lista2 = map(int,raw_input().split())

menor1 = lista1[0]
for i in range(size1):
    if(lista1[i] < menor1):
        menor1 = lista1[i]

menor2 = lista2[0]
for i in range(size2):
    if(lista2[i] < menor2):
        menor2 = lista2[i]

if(menor1 == menor2):
    print(menor1)
else:
    print(str(menor1) + str(menor2))