n,m=map(int,input().split())
a=set(map(int,input().split()))
b=set(map(int,input().split()))
c=a&b
if c:
    print(min(c))
else:
    c1=min(a)
    c2=min(b)
    if c1<c2:
        print(c1,c2,sep='')
    else:
        print(c2,c1,sep='')
