#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int dx4[] = { -1, 0, 1, 0 };
const int dy4[] = { 0, -1, 0, 1 };
const int dx8[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
const int dy8[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

const float eps = 1e-9;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, d;
	cin >> n >> d;

	int ones = 0;
	vector<int> card(n), l(n), ans;
	vector<float> a(n);
	vector<vector<int>> par(n + 1, vector<int>(10, -1));
	vector<vector<float>> dp(n + 1, vector<float>(10, -1e9));

	for (int i = 0; i < n; i++) {
		cin >> card[i];
		l[i] = card[i] % 10;
		a[i] = log2(card[i]);
		if (card[i] == 1) ones++;
	}
	
	dp[0][1] = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			dp[i + 1][j] = dp[i][j];
		}
		if (card[i] == 1) continue;
		for (int j = 0; j < 10; j++) {
			int k = (j * l[i]) % 10;
			if (dp[i][j] + eps > 0 && dp[i][j] + a[i] + eps > dp[i + 1][k]) {
				dp[i + 1][k] = dp[i][j] + a[i];
				par[i + 1][k] = j;
			}
		}
	}

	if (dp[n][d] < eps) {
		if (d == 1 && ones) cout << 1 << endl << 1;
		else cout << -1;
		return 0;
	}

	int i = n;
	int j = d;
	while (i) {
		if (dp[i][j] > dp[i - 1][j] + eps) {
			ans.push_back(card[i - 1]);
			j = par[i][j];
		}
		i--;
	}
	
	cout << ans.size() << endl;
	for (int x : ans) {
		cout << x << ' ';
	}
}