n1,n2 = map ( int, input().split())
a =[int(i) for i in input().split()]
b =[int(i) for i in input().split()]
f=0
flag=0
a.sort()
b.sort()
for i in range (n1):
    for j in range (n2):
        if a[i]==b[j] and flag==0:
            f=a[i]
            flag=1
if flag==0:
    print (min(a[0],b[0]), max(a[0],b[0]),sep="")
else:
    print(f)
        