n=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=[]
d=[1,2,3,4,5,6,7,8,9]
k=min(a)
c=min(b)
for i in range(len(d)):
    if d[i] in a and d[i] in b:
        s.append(d[i])
if len(s)>=1:
    print(min(s))
else:
    if k==c:
        print(c)
    else:
        print(str(min(k,c))+str(max(k,c)))