#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
using namespace std;
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c > '9' || c < '0') { if(c == '-') f = -1; c = getchar(); }
    while(c <= '9' && c >= '0') { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); }
    return x * f;
}
inline void write(int x) {
    if(x < 0) putchar('-'), x = -x;
    if(x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
const int maxn = 1e5 + 5, inf = -1e9;
long double dp[maxn][10];
int a[maxn];
int main(){
    int n = read(), k = read();
    for(int i = 1; i <= n; i ++) a[i] = read();
    for(int i = 0; i < 10; i ++) dp[n+1][i] = i == k ? 0 : inf;
    for(int i = n; i >= 1; i --)
        for(int j = 0; j < 10; j ++)
            dp[i][j] = max((long double)inf, max(dp[i+1][(j*a[i])%10] + log(a[i]), dp[i+1][j]));
    vector<int> v;
    int i = 1, j = 1;
    while(i <= n) {
        if(dp[i+1][j*a[i]%10] + log(a[i]) >= dp[i+1][j]){
            v.push_back(i);
            j = j * a[i ++] % 10;
        }else i ++;
    }
    if(j != k || v.empty()) cout << -1 << '\n';
    else {
        cout << v.size() << '\n';
        for(int i = 0; i < v.size(); i ++) {
            if(i > 0) cout << ' ';
            cout << a[v[i]];
        }
        cout << '\n';
    }
    return 0;
}

  		 	 	 	 		  		 						  	 			