def bubble_sort(array):
    for i in xrange(len(array) - 1):
        for j in xrange(len(array) - i - 1):
            if (array[j] > array[j + 1]):
                array[j], array[j + 1] = array[j + 1], array[j]
    return array

def min_intersection(array1, array2):
    for i in xrange(len(array1)):
        for j in xrange(len(array2)):
            if (array1[i] == array2[j]):
                return array1[i]
    return 0

n, m = map(int, raw_input().split())
first = bubble_sort(map(int, raw_input().split()))
second = bubble_sort(map(int, raw_input().split()))

min_intersection = min_intersection(first, second)

if min_intersection > 0:
    print min_intersection
elif first[0] > second[0]:
    print str(second[0]) + str(first[0])
else:
    print str(first[0]) + str(second[0])