def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    try:
        mm = min(set(a)&set(b))
    except:
        mm = False

    mina = min(a)
    minb = min(b)

    if mm:
        print(mm)
    else:
        b_number1 = str(mina) + str(minb)
        b_number2 = str(minb) + str(mina)
        print(min(b_number1, b_number2))


if __name__ == '__main__':
    main()