def pretty_integers():
    k = input().split()
    n = input().split()
    m = input().split()
    for i in range(len(n)):
        n[i] = int(n[i])
    for j in range(len(m)):
        m[j] = int(m[j])

    for i in range(1, 10):
        if i in n and i in m:
            return i
    s = ''
    if min(n) < min(m):
        s += (str(min(n)) + str(min(m)))
    else:
        s += (str(min(m)) + str(min(n)))
    return s
print(pretty_integers())