read=lambda : map(int,input().split())
n,m=read()
a=sorted(list(read()))
b=sorted(list(read()))
ans=min(a[0]*10+b[0],b[0]*10+a[0])
for t in a:
    if t in b:
        ans=min(ans,t)
for t in b:
    if t in a:
        ans=min(ans,t)
print(ans)

