def nice_numbers(lst1, lst2):
    a, b = set(lst1), set(lst2)
    if a & b:
        return min(a & b)
    else:
        c, d = min(a), min(b)
        return str(min(c, d)) + str(max(c, d))


n, m = [int(i) for i in input().split()]
k1 = [int(j) for j in input().split()]
k2 = [int(z) for z in input().split()]
print(nice_numbers(k1, k2))
