#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

double d[100100][10];
ll val[100100][10],id[100100][10];
ll m[100100];
ll n,k;

int main(){

cin>>n>>k;
for(ll i=1;i<=n;++i)cin>>m[i];

for(ll i=0;i<n;++i){
  for(ll j=0;j<10;++j){
    d[i+1][j]=d[i][j];
    val[i+1][j]=val[i][j];
    id[i+1][j]=id[i][j];
    }
  for(ll j=0;j<10;++j){
    if(d[i][j]==0)continue;
    if(d[i][j]+log10(m[i+1])>d[i+1][(j*m[i+1])%10]){
      d[i+1][(j*m[i+1])%10]=d[i][j]+log10(m[i+1]);
      val[i+1][(j*m[i+1])%10]=j;
      id[i+1][(j*m[i+1])%10]=i+1;
      }
    }
  if(log10(m[i+1])>d[i+1][m[i+1]%10]){
    d[i+1][m[i+1]%10]=log10(m[i+1]);
    val[i+1][m[i+1]%10]=-1;
    id[i+1][m[i+1]%10]=i+1;
    }
  }

/*
for(ll i=0;i<=n;++i){
  cout<<i<<" "<<m[i]<<endl;
  for(ll j=0;j<10;++j){
    if(id[i][j])cout<<j<<" "<<id[i][j]<<" "<<val[i][j]<<" "<<d[i][j]<<endl;
    }
  cout<<endl;
  }
*/

if(id[n][k]==0){
  cout<<"-1"<<endl;
  return 0;
  }

vector<ll> res;
ll wh=n,x=k;
while(true){
  ll t=wh;
  wh=id[wh][x];
  x=val[t][x];

  //cout<<wh<<" "<<x<<endl;
  res.push_back(m[wh]);
  --wh;
  if(x==-1)break;
  }

cout<<res.size()<<endl;
for(ll i : res)cout<<i<<" ";cout<<endl;

return 0;
}
/*
6 4
4 11 8 2 1 13

*/
