n,m = map(int, input().split())
N = list(map(int, input().split()))
M = list(map(int, input().split()))
cache = []
for i in range(len(N)):
    for j in range(len(M)):
        if N[i] != M[j]:
            cache.append(int(str(N[i])+str(M[j])))
            cache.append(int(str(M[j])+str(N[i])))
        else:
            cache.append(M[j])
print(min(cache))
