input()
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
X = set(list1).intersection(list2)
if len(X) != 0:
    print(min(X))
    exit()
Min = []
Min.append(min(list1))
if min(list2) not in Min:
    Min.append(min(list2))
print(*(sorted(Min)), sep="")
