#include<bits/stdc++.h>
using namespace std;
int a[100001];
double b[100001];
double dp[100001][10];
bool pake[100001];
int cnt;
int n, d;
double F(int now, int dig){
//	printf("what %d %d\n", now, dig);
	
	if (now == n){
		if (dig == d) return dp[now][dig] = 0;
		return dp[now][dig] = -1e9;
	}
	if (dp[now][dig] != -1) return dp[now][dig];
//	printf("%d %d\n", now, dig);
	double ans1 = F(now+1, (dig*a[now])%10) + b[now];
	double ans2 = F(now+1, dig);
	return dp[now][dig] = max(ans1, ans2);
}
void backtrack(int now, int dig){
	if (now == n) return;
	double ans1 = dp[now+1][(dig*a[now])%10] + b[now];
	double ans2 = dp[now+1][dig];
	if (ans1>ans2){
		pake[now] = true;
		backtrack(now+1, (dig*a[now])%10);
		return;
	}
	backtrack(now+1, dig);
}
int main(){
	scanf("%d%d", &n, &d);
	for (int i = 0; i < 100001; i++){
		for (int j = 0;j < 10;j++){
			dp[i][j] = -1;
		}
	}
	for (int i = 0; i < n; i++){
		cin >> a[i];
		b[i] = log(a[i]);
	}
	double temp = F(0, 1);
	
	if (temp<0){
		printf("-1\n");
		return 0;
	}
	backtrack(0, 1);
	for(int i = 0; i < n; i++){
		if (pake[i]) cnt++;
	}
	if (cnt== 0){
			printf("-1\n");
		return 0;
	}
	printf("%d\n", cnt);
	for (int i = 0; i < n; i++){
		if (pake[i]) printf("%d ", a[i]);
	}
	printf("\n");
}
