n, m = map(int, input().split())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
arr = []
for i in a1:
    for j in a2:
        if i == j:
            arr.append(i)
        else:
            mn = min(i , j)
            mx = max(i, j)
            arr.append((mn * 10 + mx))
print(min(arr))