n=input()
a=list(map(int, input().split()))
b=list(map(int, input().split()))
res=100000
for i in range(len(a)):
    for j in range(len(b)):
        if (a[i]==b[j] and a[i]<res):
            res=a[i]
        else:
            if (min((a[i]*10+b[j]), (b[j]*10+a[i]))<res):
                res=min((a[i]*10+b[j]), (b[j]*10+a[i]))
print (res)