def pretty(m1,m2,s1,s2):
    ar=[]

   
    for i in s1:
        if i in s2:
            ar.append(i)
    if ar!=[]:
        return(min(ar))
    elif m1<m2:
        s=str(m1)+str(m2)
        return(s)
    elif m2<m1:
        s=str(m2)+str(m1)
        return(s)


m,n=map(int,input().split())
s1=list(map(int,input().split()[:m]))
s2=list(map(int,input().split()[:n]))
m1=min(s1)
m2=min(s2)
x=pretty(m1,m2,s1,s2)
print(x)
