n,m=map(int,input().split())
l=list(map(str,input().split()))
l1=list(map(str,input().split()))
x,ans=[],[]
for i in range(n):
    for j in range(m):
        x.append(list(set(l[i]+l1[j]))) 
        x.append(list(set(l1[j]+l[i])))
for i in range(len(x)):
    z="".join(x[i])
    z=int(z)
    ans.append(z)
print(min(ans))