a, b = map(int,input().split())
A = set(list(map(int, input().split())))
B = set(list(map(int, input().split())))
C = A.intersection(B)
if len(C) != 0:
    print(min(C))

else:
    print(min(min(A),min(B)), end = '')
    print(max(min(A),min(B)))