n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
b.sort()
ans=-1
for i in range(len(a)):
    if a[i] in b:
        ans=a[i]
        break
if ans!=-1:
    print(ans)
else:
    x=min(a)
    y=min(b)
    if x==y:
        print(x)
    else:
        ans=(min(x,y)*10)+max(x,y)
        print(ans)