l1, l2 = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
min_sovp = 10
for i in range(l1):
    if (arr1[i] in arr2):
        if arr1[i]<min_sovp:
            min_sovp=arr1[i]
if min_sovp==10:
    i = min(arr1)
    j = min(arr2)
    if i<j:
        print(str(i)+str(j))
    else:
        print(str(j)+str(i))
else:
    print(str(min_sovp))