n,m=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l1.sort()
l2.sort()
c=1
for i in l1:
    if i in l2:
        c=0
        print(i)
        break
if c:
    if l1[0]<l2[0]:
        print(l1[0]*10+l2[0])
    else:
        print(l2[0]*10+l1[0]) 
        
        
