lengths = raw_input()
lengths = lengths.split()
lengths = map(int, lengths)

firstList = raw_input()
firstList = firstList.split()
firstList = map(int, firstList)
firstList = sorted(firstList)

secondList = raw_input()
secondList = secondList.split()
secondList = map(int, secondList)
secondList = sorted(secondList)

def findMinNumber(smallerList, higherList):
    found = False
    for i in smallerList:
        if(i in higherList):
            print(i)
            found = True
            break
    if(not found):
        if(smallerList[0] < higherList[0]):
            print(str(smallerList[0]) + str(higherList[0]))
        else:
            print(str(higherList[0]) + str(smallerList[0]))

if(lengths[0] < lengths[1]):
    findMinNumber(firstList, secondList)
else:
    findMinNumber(secondList, firstList)

