n, m = map(int, input().split())
array_n = list(map(int, input().split()))
array_m = list(map(int, input().split()))
x = 10
for i in range(n):
    if array_n[i] in array_m:
        if array_n[i] < x:
            x = array_n[i]
if x < 10:
    print(x)
else:
    a = min(array_n)
    b = min(array_m)
    print(10 * min(a, b) + max(a, b))
