n,m=map(int,input().split())
data=input()
s=data.split()
a=[int(x) for x in s]
data=input()
s1=data.split()
b=[int(x) for x in s1]
mina=10
for i in range(n):
   for j in range(m):
       if a[i]==b[j]:
           if a[i]<mina:
               mina=a[i]
if mina==10:
    a=sorted(a)
    b=sorted(b)
    if a[0]>=b[0]:
        mina=b[0]*10+a[0]
    else:
        mina=b[0]+a[0]*10
print(mina)
