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):
    print(min(a.intersection(b)))
elif(len(a.intersection(b))==0):
    if(int(str(min(a))+str(min(b)))<=int(str(min(b))+str(min(a)))):
        print(int(str(min(a))+str(min(b))))
    else:
        print(int(str(min(b))+str(min(a))))
