input()
N=list(map(int,input().split()))
M=list(map(int,input().split()))

S = set(M).intersection(set(N))
if len(S) != 0:
    print(min(S))
else:
    if min(N) < min    (M):
        print(min(N) * 10 + min(M))
    else:
        print(min(M) * 10 + min(N))