#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
double d[100010][10];
int prv[100010][10];
int a[100010];
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j < 10; j++) {
			d[i][j] = -1;
			prv[i][j] = -1;
		}
	}
	d[0][1] = 0;
	for (int i = 0; i < n; i++) {
		double p = log(a[i]);
		for (int j = 0; j < 10; j++) {
			if (d[i][j] < -0.1) continue;
			int x = j * a[i] % 10;
			if (d[i+1][x] < d[i][j] + p) {
				d[i+1][x] = d[i][j] + p;
				prv[i+1][x] = j;
			}
		}
		for (int j = 0; j < 10; j++) {
			if (d[i][j] < -0.1) continue;
			if (d[i+1][j] < d[i][j]) {
				d[i+1][j] = d[i][j];
				prv[i+1][j] = -1;
			}
		}
	}
	if (d[n][k] < -0.1) {
		puts("-1");
		return 0;
	}
	vector<int> ans;
	for (int i = n; i > 0; i--) {
		int xt = prv[i][k];
		if (xt == -1) continue;
		ans.push_back(a[i-1]);
		k = xt;
	}
	if (!ans.size()){ 
		puts("-1");
		return 0;
	}
	printf("%d\n", ans.size());
	for (int i = 0; i < ans.size(); i++) {
		printf("%d%c", ans[i], i + 1 == ans.size() ? '\n' : ' ');
	}
	return 0;
}
