#include "bits/stdc++.h"
using namespace std;
const int maxx = 100005;
int a[maxx];
double f[maxx][10];
int trace[maxx][10];
void solve()
{
    int n,m; cin >> n >> m;
    for(int i = 1; i <= n ; ++i) cin >> a[i];
    for(int i = 0 ; i <= n ; ++i )
    {
        for(int j = 0 ; j < 10 ; ++j)
        {
            f[i][j] = -1e300;
            trace[i][j] = - 1;
        }
    }
    f[0][1] = 1;
    for(int i = 1; i <= n ; ++i)
    {
        for(int j = 0 ; j < 10 ; ++j) f[i][j] = f[i - 1][j];
        for(int j = 0 ; j < 10 ; ++j)
        {
            int tmp = j * a[i] % 10 ;
            if(f[i][tmp] < f[i - 1][j] + log(a[i]))
            {
                f[i][tmp] = f[i - 1][j] + log(a[i]);
                trace[i][tmp] = j;
            }
        }
    }
    vector<int>rez;
	while(n){
		if (trace[n][m] != -1){
			rez.push_back(a[n]);
			m = trace[n][m];
		}
        --n;
	}
	if(rez.size() == 0) cout << -1 << '\n';
	else{
		cout << rez.size() << '\n';
		for(int i:rez) cout << i << " ";
		cout << '\n';
	}
}
signed main()
{
    solve();
    return 0;
}
