
_ = input()

lst = []

for _ in range(2):
    lst.append(list(map(int, input().split())))

a = set(lst[0]) & set(lst[1])
num = [min(lst[0]),  min(lst[1])]
num.sort()

if len(a) and (min(a) < (num[0] * 10 + num[1])):
    print(min(a))
elif num[0] == num[1]:
    print(num[0])
else:
    print(num[0] * 10 + num[1])
