n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=set(a)
b=set(b)
if len(a.intersection(b))!=0:
    k=a.intersection(b)
    print(min(k))
else:

    k1=min(a)
    k2=min(b)
    if k1==k2:
        print(k1)
    else:
        print(min(k1,k2),end='')
        print(max(k1,k2))