#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main(){
    long n; int d;
    cin>>n>>d;
    int a[n+1];
    double dp[n+1][10];
    int pre[n+1][10];
    for(int i=0;i<=n;i++) for(int j=0;j<10;j++) {
    dp[i][j]=-1000; pre[i][j]=-1;}
    dp[0][1]=0;
    for (int i=1;i<=n;i++){
            cin>>a[i];
		for (int j=0;j<10;j++)
			dp[i][j]=dp[i-1][j];
		for (int j=0;j<10;j++){
			int k=j*a[i]%10;
			double t=dp[i-1][j]+log(a[i]);
if(t>0&&dp[i][k]<t){
				dp[i][k]=t;
				pre[i][k]=j;
			}
		}
	}
	vector<int>rez;
	while(n){
		if (pre[n][d]!=-1){
			rez.push_back(a[n]);
			d=pre[n][d];
		}
        n--;
	}
	if(rez.size()==0) cout<<-1<<endl;
	else{
		cout<<rez.size()<<endl;
		for(int i:rez) cout<<i<<" ";
		cout<<endl;
	}
    return 0;
}