N, M = map(int, input().split())
first = list(map(int,input().split()))
second = list(map(int,input().split()))
ans = ''
ch = 10
if N>=M:
    for i in range(N):
        if first[i] in second and first[i]<ch:
            ch=first[i]
else:
    for i in range(M):
        if second[i] in first and second[i]<ch:
            ch=second[i]
if ch<10:
    print(ch)
elif min(first) < min(second):
    print(str(min(first)) + str(min(second)))
else:
    print(str(min(second)) + str(min(first)))
