input()
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
x = min(arr1)
y = min(arr2)
if set(arr1) & set(arr2):
    print(min(list(set(arr1)&set(arr2))))
else:
    print(str(min(x, y)) + str(max(x, y)))#kek