def intersection(lst1, lst2):
    return list(set(lst1) & set(lst2))

list_sizes = map(int, raw_input().split())
list_a = map(int, raw_input().split())
list_b = map(int, raw_input().split())

min_a = min(list_a)
min_b = min(list_b)

min_total = min(min_a, min_b)
max_total = max(min_a, min_b)

inter = intersection(list_a, list_b)

if (list_a.count(min_total) > 0 and list_b.count(min_total) > 0):
    print(min_total)
elif (list_a.count(max_total) > 0 and list_b.count(max_total) > 0):
    print(max_total)
elif (len(inter) > 0):
    print(min(inter))
else:
    print(str(min_total) + str(max_total))
