#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr<<#x<<" = "<<x<<endl

const int maxn=1e5+10;

double dp[maxn][12];
int pre[maxn][12];
int a[maxn];
double b[maxn];
bool vis[maxn][12],ok[maxn][12];

int main(){
    ios::sync_with_stdio(false);
    //freopen("in.txt","r",stdin);

    int n,k;cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i],b[i]=log10(a[i]);
    memset(dp,0,sizeof(dp));
    memset(ok,0,sizeof(ok));
    ok[0][1]=true;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=9;j++){
            if(ok[i-1][j]){
                dp[i][j]=dp[i-1][j];
                pre[i][j]=j;
                vis[i][j]=false;
                ok[i][j]=true;
            }
        }
        for(int j=0;j<=9;j++){
            if(ok[i-1][j]&&dp[i-1][j]+b[i]>dp[i][j*a[i]%10]){
                //debug(j*a[i]%10);
                dp[i][j*a[i]%10]=dp[i-1][j]+b[i];
                pre[i][j*a[i]%10]=j;
                vis[i][j*a[i]%10]=true;
                ok[i][j*a[i]%10]=true;
            }
        }
    }
    /*for(int i=1;i<=n;i++){
        for(int j=0;j<=9;j++){
            cout<<ok[i][j]<<" ";
        }
        cout<<"\n";
    }*/
    vector<int>ans;
    bool f=true;
    while(n){
        if(!ok[n][k]){
            f=false;break;
        }
        if(vis[n][k]) ans.push_back(a[n]);
        k=pre[n][k];
        --n;
    }
    if(!f||ans.size()==0) cout<<"-1\n";
    else{
        cout<<ans.size()<<"\n";
        for(int i=0;i<ans.size();i++) cout<<ans[i]<<" ";
        cout<<"\n";
    }

}


