def intersection(lst1, lst2): 
    lst3 = [value for value in lst1 if value in lst2] 
    return lst3 

[n, m] = map(int, raw_input().split())

list1 = map(int, raw_input().split())
list2 = map(int, raw_input().split())

inter = intersection(list1, list2)
if inter:
    print(min(inter))
else:
    digits = [min(list1), min(list2)]
    first = min(digits)
    second = max(digits)
    print(int(str(first) + str(second)))