n, m = map(int, input().split())
N = list(map(int, input().split()))
M = list(map(int, input().split()))
U = set(N) & set(M)
if (len(U)!=0):
    print(min(U))
else:
    q, w = min(N), min(M)
    if (q>w):
        q, w = w, q
    print (q, w, sep="")