#http://codeforces.com/problemset/problem/870/A

#not done

def smallest(array):
    return min(array)

def getPretty1(array1,array2):
    val1 = smallest(array1)
    val2 = None
    for item in array2:
        if item == val1:
            val2 = item
            break
    if val2 == None:
        val2 = smallest(array2)
    if val1 == val2:
        return val1
    elif val1 > val2:
        return val1 + 10*val2
    return val2 + 10*val1

def getPretty(array1,array2):
    # Getting first pass
    min1 = min(array1)
    RA = None
    for item in array2:
        if item == min1:
            RA = min1
    if RA == None:
        min2 = min(array2)
        if min1 < min2:
            RA = min1*10 + min2
        else:
            RA = min1 + min2*10
    min1 = min(array2)
    for item in array1:
        if item == min1 and RA > item:
            RA = item
    min2 = min(array1)
    if RA > min1*10 + min2:
        RA = min1*10 + min2
    elif RA > min1 + min2*10:
        RA = min1 + min2*10
    duplicates = []
    for i in range(len(array1)):
        for j in range(len(array2)):
            if array1[i] == array2[j]:
                duplicates.append(array1[i])
    if duplicates != []:
        if RA > min(duplicates):
            return min(duplicates)
    return RA
    

while True:
    try:
        junk = input()
        arr1 = input()
        arr2 = input()
        arr1 = arr1.split(" ")
        arr2 = arr2.split(" ")
        for i in range(len(arr1)):
            arr1[i] = int(arr1[i])
        for i in range(len(arr2)):
            arr2[i] = int(arr2[i])
        a = (getPretty(arr1,arr2))
        print(a)
    except EOFError:
        break
