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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define pf push_front
#define sz(x) (int)(x).size()
#define lb lower_bound 
#define ub upper_bound 
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef long double ld;
typedef map<int,int> mii;

const int MOD = 1e9+7;
const ld PI = acos((ld)-1);
const ll INF = 1e16;

void solve () {
	int n,digit;
	cin >> n >> digit;
	vi arr(n+1);
	for (int i = 1;i <= n;++i) {
		cin >> arr[i];
	}
	ld dp[n+1][10];
	pii parent[n+1][10];
	for (int i = 0;i <= n;++i) {
		for (int j = 0;j < 10;++j) {
			dp[i][j] = -INF;
			parent[i][j] = {-1,-1};
		}
	}
	dp[0][1] = 0;
	for (int i = 1;i <= n;++i) {
		for (int d = 0;d < 10;++d) {
			dp[i][d] = dp[i-1][d];
			parent[i][d] = parent[i-1][d];
		}
		for (int d = 0;d < 10;++d) {
			int lastDigit = (arr[i]*d)%10;
			if (dp[i-1][d] != -INF && dp[i][lastDigit] <= dp[i-1][d]+log(arr[i])) {
				dp[i][lastDigit] = dp[i-1][d]+log(arr[i]);
				parent[i][lastDigit] = {i-1,d};
			}
		}
	}
	if (parent[n][digit] == make_pair(-1,-1)) {
		cout << -1 << '\n';
		return;
	}
	vi res;
	int lastDigit = digit;
	for (int i = n;i >= 1;--i) {
		if (parent[i][lastDigit] != parent[i-1][lastDigit]) {
			res.pb(arr[i]);
			lastDigit = parent[i][lastDigit].se;
		}
	}
	cout << res.size() << '\n';
	for (int& i: res) {
		cout << i << " ";
	}

}

int main () {

#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output1.txt","w",stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}

	