n,m=input().split()

a1=list(map(int,input().split()))
a2=list(map(int,input().split()))


z=list(set(a1).intersection(set(a2)))
for i in a1:
    for j in a2:
        z.append(int(str(i)+str(j)))

for i in a2:
    for j in a1:
        z.append(int(str(i)+str(j)))
        
z=sorted(z)
print(z[0])
