n, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
flag = 1
ans = 10

for i in A:
    for j in B:
        if i == j and i < ans:
            ans = i
            flag = 0
if flag:
    a = min(A)
    b = min(B)    
    if a < b:
        print(str(a) + str(b))
    else:
        print(str(b) + str(a))
else:
    print(ans)