#include <algorithm>
#include <fstream>
#include <sstream>
#include <string>

int input[1000];
int selected[1000];
int indices[1000];

template<typename array>
bool next_selection(array begin, array end, int max)
{
    array curr = end;
    do
    {
        --curr;
        ++(*curr);
        if (*curr < max)
        {
            ++curr;
            while (curr != end)
            {
                *curr = *(curr - 1) + 1;
                ++curr;
            }
            return true;
        }
    }
    while (begin != curr);
    return false;
}

int main()
{
    std::ifstream in("enigmatic.in");
    std::ofstream out("enigmatic.out");
    std::string word;
    in >> word;
    int n;
    in >> n;
    for (int i = 0; i < n; ++i)
    {
        in >> input[i];
    }
    std::sort(input, input + n);
    for (int size = 1; ; ++size)
    {
        for (int i = 0; i < size; ++i)
        {
            indices[i] = i;
        }
        do
        {
            for (int i = 0; i < size; ++i)
            {
                selected[i] = input[indices[i]];
            }
            do
            {
                //TODO: optimize this
                std::ostringstream oss;
                for (int i = 0; i < size; ++i)
                {
                    oss << selected[i];
                }
                if (oss.str() == word)
                {
                    out << size << std::endl;
                    for (int i = 0; i < size; ++i)
                    {
                        out << selected[i] << std::endl;
                    }
                    return 0;
                }
            }
            while (std::next_permutation(selected, selected + size));
        } while (next_selection(indices, indices + size, n));
    }
}

