min3=10
n, m=map(int, input().split())
s=input().split(' ')
sp1=[int(i) for i in s]
s=input().split(' ')
sp2=[int(i) for i in s]
for i in range (n):
    for j in range (m):
        if sp1[i]==sp2[j] and min3>sp1[i]:
            min3=sp1[i]
min1=min(sp1)
min2=min(sp2)

if (not min3==10):
    print(min3)
elif (min1<min2):
    print(min1, end='')
    print(min2)
elif (min1>min2):
    print(min2, end='')
    print(min1)
else:
    print(min1)
