input()
s1 = set(int(i) for i in input().split())
s2 = set(int(i) for i in input().split())

commons = s1 & s2

if commons:
    print(min(commons))
else:
    m1, m2 = min(s1), min(s2)
    print("{}{}".format(m1 if m1 < m2 else m2, m2 if m1 < m2 else m1))