x, y=map(int, input().split())
A=[0]*x
B=[0]*y
A=list(map(int, input().split()))
B=list(map(int, input().split()))
Min=10
k=0
for i in range(x):
    for j in range(y):
        if A[i]==B[j] and A[i]<Min:
            Min=A[i]
            k=1
if k==1:
    print(Min)
else:
    print(min(min(A), min(B))*10+max(min(A), min(B)))

       
