n, m = [int(i) for i in input().split()]
n_list = [int(i) for i in input().split()]
n_list.sort()
m_list = [int(i) for i in input().split()]
m_list.sort()

a = set(n_list) & set(m_list)
if len(a) > 0:
    print(min(a))
else:
    min_a = n_list[0]
    min_b = m_list[0]
    print(str(min(min_a, min_b)) + str(max(min_a, min_b)))
