n, m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
f = False
for i in range(1, 10):
    if i in a and i in b:
        print(i)
        f = True
        break
if not f:
    m1 = min(a)
    m2 = min(b)
    if m1 < m2:
        print(m1 * 10 + m2)
    else:
        print(m2 * 10 + m1)