n, m = map(int, input().split())
a, b = set(map(int, input().split())), set(map(int, input().split()))
if a & b:
    print(min(a & b))
else:
    x, y = min(a), min(b)
    print(10 * x + y if x < y else 10 * y + x)