n, m = map(int, raw_input().split())
a1 = map(int, raw_input().split())
a2 = map(int, raw_input().split())

m = 2000000000
for el in a1:
    if el in a2 and el < m:
        m = el

m_2 = str(min(min(a1), min(a2))) + str(max(min(a1), min(a2)))
print min(m, int(m_2))