#include <bits/stdc++.h>
using namespace std;
using db = long double;
const int N = 1e5 + 5;
const db eps = 1e-8, inf = 1e18;
int n, d, a[N], pre[N][10];
db dp[N][10];
inline int sgn(db x)
{
    return (x<-eps ? -1 : x>eps);
}
inline bool Max(db &x, db y)
{
    if(sgn(x-y)<0)
    {
        x = y;
        return true;
    }
    return false;
}
int main()
{
    scanf("%d%d", &n, &d);
    for(int i=1; i<=n; i++) scanf("%d", a+i);
    for(int i=0; i<=n; i++) for(int j=0; j<=9; j++) dp[i][j] = -inf, pre[i][j] = -1;
    dp[0][1] = 0;
    for(int i=1; i<=n; i++)
        for(int j=0; j<=9; j++)
        {
            if(sgn(dp[i-1][j]+inf)==0) continue;
            if(Max(dp[i][(j*a[i])%10], dp[i-1][j]+log(a[i]))) pre[i][(j*a[i])%10] = j;
            if(Max(dp[i][j], dp[i-1][j])) pre[i][j] = -1;
        }
    if(sgn(dp[n][d]+inf)==0) puts("-1");
    else
    {
        int x = n, y = d;
        vector<int> res;
        while(x)
        {
            if(~pre[x][y])
            {
                res.push_back(a[x]);
                y = pre[x][y];
            }
            --x;
        }
        int k = res.size();
        if(d==1&&!k) puts("-1");
        else
        {
            printf("%d\n", k);
            for(int i=0; i<k; i++) printf("%d%c", res[i], " \n"[i==k]);
        }
    }
    return 0;
}
