n,m=(int(i) for i in input().split())
l1=sorted([int(i) for i in input().split()])
l2=sorted([int(i) for i in input().split()])
c=0
for i in range(n):
    for j in range(m):
        if(l1[i]==l2[j]):
            c=1
            break
    if(c==1):
        break
if(c==1):
    print(l1[i])
else:
    k=min(l1[0],l2[0])
    k1=max(l1[0],l2[0])
    print(str(k)+str(k1))