lists = input().split()
list1 = list(map(int,input().split()))
list2 = list(map(int,input().split()))
eqs = []
for i in list1:
    for j in list2:
        if i == j:
            eqs.append(j)
if eqs:
    print(min(eqs))
else:
    nums = [min(list1),min(list2)]
    print(min(nums),max(nums),sep = '')
