n ,m = map(int, input().split())
arr1 = []
arr2 = []
nums = []

arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))

arr1.sort()
arr2.sort()

for i in range(n):
    for j in range(m):
        if arr1[i] == arr2[j]:
            nums.append(arr1[i])

num = min(arr1[0], arr2[0]) * 10 + max(arr1[0], arr2[0])
if len(nums) > 0:
    print(min(num, min(nums)))
else:
    print(num)