#include <bits/stdc++.h>

using namespace std;
const int inf = 1e9 + 233;

int n, d, x;
int zy[100010][10], a[100010], pos[10], pos2[10], zyd[100010][10];
double f[10], g[10];
vector <int> ans;

int main()
{
    scanf("%d%d", &n, &d);

    for (int i = 0; i < 10; i++)
        f[i] = g[i] = -inf;
    f[1] = g[1] = 0;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &x);
        a[i] = x;
        double xx = log(x);

        for (int j = 0; j < 10; j++)
            zy[i][j] = zy[i - 1][j], zyd[i][j] = zyd[i - 1][j];

        for (int j = 0; j < 10; j++)
        {
            int nxt = j * a[i] % 10;

            // printf("i:%d j:%d nxt:%d\n", i, j, nxt)

            if (g[nxt] < f[j] + xx)
            {
                g[nxt] = f[j] + xx;
                zy[i][nxt] = pos[j];
                zyd[i][nxt] = j;
                pos2[nxt] = i;
            }
        }

        for (int j = 0; j < 10; j++)
            f[j] = g[j], pos[j] = pos2[j];//, printf("i:%d j:%d f[j]:%.3lf pos[j]:%d %d %d\n", i, j, f[j], pos[j], zy[i][j], zyd[i][j]);
    }

    if (f[d] <= 0)
        puts("-1");
    else
    {
        int x = pos[d];
        while (x)
        {
            // printf("x:%d d:%d %d %d\n", x, d, zy[x][d], zyd[x][d]);
            ans.push_back(a[x]);
            int nxtd = zyd[x][d];
            int nxtx = zy[x][d];
            x = nxtx; d = nxtd;
        }

        printf("%d\n", ans.size());
        sort(ans.begin(), ans.end());
        for (int i = 0; i < ans.size(); i++)
            printf("%d ", ans[i]);
    }
}