import sys
put=input().split()
put1=input().split()
for i in put1:
    i=int(i)
put2=input().split()
for n in put2:
    n=int(n)
k=0

    
for i in put1:
    for n in put2:
        if int(i)== int(n):
            if int(n)<int(k) and int(k)!=0:
                k=n
            elif int(k)==0 :
                k=n
else:
    if int(k)>0:
        print(k)
        sys.exit()
    else:
        if min(put1)>min(put2):
            print(str(min(put2))+str(min(put1)))
        else:
            print(str(min(put1))+str(min(put2)))
