n, m = map(int, input().split())

A = list(map(str, input().split()))
B = list(map(str, input().split()))

A.sort()
B.sort()

p = True

for i in range(0, n):
    for k in range(0, m):
        if A[i] == B[k]:
            print(A[i])
            p = False
            break
    if p == False:
        break

if A[0] > B[0] and p == True:
    print(str(B[0] + A[0]))
elif A[0] < B[0] and p == True:
    print(str(A[0] + B[0]))
        
