n = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))

res = []

for i in a:
    for j in b:
        if i!=j:
            res.append(min(i,j)*10 + max(i,j))
        else:
            res.append(i);   

print ( min( res ))
