n, m=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
k=10
for i in range (len(a)):
    for j in range(len(b)):
        if (a[i]==b[j]) and (a[i]<k):
            k=a[i]
            
if k!=10:
    print(k)
else:
    a1=min(a)
    a2=min(b)
    b1=min(a1, a2)
    b2=max(a1, a2)
    print(10*b1+b2)