n,m=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
l=[]
for i in range(0,len(a)):
    for j in range(0,len(b)):
        if(a[i] in b):
            l.append(a[i])
            break
        else:
            l.append(int(str(a[i])+str(b[j])))
for i in range(0,len(b)):
    for j in range(0,len(a)):
        if(b[i] in a):
            l.append(b[i])
            break
        else:
            l.append(int(str(b[i])+str(a[j])))
print(min(l))