string = input()
string = input()
string = string.split(" ")
nums1 = list()
nums2 = list()
for num in string:
    if num.isnumeric():
        nums1.append(int(num))
string = input()
string = string.split(" ")
for num in string:
    if num.isnumeric():
        nums2.append(int(num))
num1 = min(nums1)
num2 = min(nums2)
intersection = list(set(nums1) & set(nums2))
if len(intersection)>0:
    print(str(min(intersection)))
elif num1 > num2:
    print(str(num2)+str(num1))
else:
    print(str(num1)+str(num2))
