n,m=[int(x) for x in input().split(" ")]
l1=[int(x) for x in input().split(" ")]
l2=[int(x) for x in input().split(" ")]
common=list(set(l1) & set(l2))
if len(common):
    print(min(common))
else:
    l1=min(l1)
    l2=min(l2)
    print(l1,l2,sep="") if l1<l2 else print(l2,l1,sep="")