#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int max_n = 1e5+100;
ll a[max_n];
int d,n;
double dp[max_n][10];
double b[max_n];
pii mp1[max_n][10];
bool mp2[max_n][10];
inline int get(ll num)
{
	return num%10;
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>d;
	for (int i=1;i<=n;++i)cin>>a[i];
	for (int i=1;i<=n;++i)b[i]=log(a[i]);
	for (int i=0;i<=n;++i)
	{
		for (int j=0;j<=9;++j)
		{
			dp[i][j]=-10000;
			mp1[i][j]=pii(-1,-1);
			mp2[i][j]=false;
		}
	}
	for (int i=1;i<=n;++i)dp[i][get(a[i])]=b[i],mp2[i][get(a[i])]=true;
	
	
	
	for (int i=1;i<=n;++i)
	{
		for (int j=0;j<=9;++j)
		{
			if (dp[i][j]<dp[i-1][j])
			{
				dp[i][j]=dp[i-1][j];
				mp1[i][j]=pii(i-1,j);
				mp2[i][j]=false;
			}
			if (dp[i-1][j]==-10000)continue;
			int id = get(j*a[i]);
			if (dp[i][id]<dp[i-1][j]+b[i])
			{
				dp[i][id]=dp[i-1][j]+b[i];
				mp1[i][id]=pii(i-1,j);
				mp2[i][id]=true;
			}
		}
	}
	
	vector<int> ans;
	pii p = pii(n,d);
	while (p.first!=-1)
	{
		if (mp2[p.first][p.second])
		{
			ans.push_back(a[p.first]);
		}
		p = mp1[p.first][p.second];
	}
	if (ans.empty())
	{
		cout<<-1<<endl;
		return 0;
	}
	cout<<ans.size()<<endl;
	for (int num:ans)cout<<num<<" ";
	cout<<endl;
}