#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int maxn=1e5+5;
const int N = 1e3+5;
int n,d,a[maxn];
double lg[N],nw[11],go[11];
pair<int,int>to[maxn][11];
double dp[maxn][11];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	for(int i = 1;i <= 1000;i++) lg[i] = log10(i);

	cin >> n >> d;
	for(int i = 0;i <= n;i++) for(int j = 0;j < 10;j++) dp[i][j] = -1;
	for(int i = 1;i <= n;i++){
		int x; cin >> x;
		a[i] = x;
		for(int j = 0;j < 10;j++) nw[j] = go[j] = -1;
		nw[x % 10] = lg[x];
		for(int j = 0;j < 10;j++){
			if(dp[i-1][j] == -1) continue;
			int now = (j * x) % 10;
			if(dp[i-1][j] + lg[x] > nw[now]){
				nw[now] = dp[i-1][j] + lg[x];
				go[now] = j;
			}
		}
		for(int j = 0;j < 10;j++){
			dp[i][j] = dp[i-1][j];
			to[i][j] = {0,j};
			if(nw[j] > dp[i][j]){
				dp[i][j] = nw[j];
				to[i][j] = {1,go[j]};
			}
		}
	}
	// cout<<dp[n][d]<<'\n';
	if(dp[n][d] == -1) return cout<<-1,0;
	vector<int>ans;
	for(int i = n;i >= 1;i--){
		if(d == -1) break;
		if(to[i][d].first == 1) ans.push_back(a[i]);
		d = to[i][d].second;
	}
	cout<<(int)ans.size()<<'\n';
	for(auto i : ans) cout<<i<<' ';
}