n,m=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l=l1+l2
a=min(l)
if a in l1 and a in l2:
    print(a)
else:
    if a in l1:
        b=min(l2)
        print(a*10+b)
    else:
        b=min(l1)
        print(b*10+a)
