def has_eq(a, b):
    eq = set()
    if len(a) < len(b):
        for x in a:
            if x in b:
                eq.add(x)
    else:
        for x in b:
            if x in a:
                eq.add(x)
    if eq:
        return min(eq)
    if min_A < min_B:
        return str(min_A) + str(min_B)
    else:
        return str(min_B) + str(min_A)


input()

a = list(map(int, input().split()))
b = list(map(int, input().split()))

min_A = min(a)
min_B = min(b)

print(has_eq(a, b))