#include <iostream>
#include <vector>
#include <bitset>
#include <random>
#include <cmath>
#include <algorithm>

using namespace std;

const int MAXN = 1e5 + 7;
const long double EPS = 1e-9;
const long double INF = 1e18;

long double dp[MAXN][10];
int path[MAXN][10];

bool lseq(long double a, long double b) {
    return a - b < EPS;
}

int main() {
#ifdef LOCAL
    freopen("a.in", "r", stdin);
    freopen("a.out", "w", stdout);
#endif
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int n, d;
    cin >> n >> d;

    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }

    fill(&path[0][0], &path[0][0] + MAXN * 10, -1);
    fill(&dp[0][0], &dp[0][0] + MAXN * 10, -INF);
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < 10; ++j) {
            dp[i][j] = dp[i - 1][j];
            path[i][j] = 11;
        }
        if (lseq(dp[i][a[i] % 10], log(a[i]))) {
            dp[i][a[i] % 10] = log(a[i]);
            path[i][a[i] % 10] = -1;
        }
        for (int j = 0; j < 10; ++j) {
            long double new_res = dp[i - 1][j] + log(a[i]);
            if (lseq(dp[i][(j * a[i]) % 10], new_res)) {
                dp[i][(j * a[i]) % 10] = new_res;
                path[i][(j * a[i]) % 10] = j;
            }
        }
    }

    vector<int> ans;
    if (lseq(dp[n][d], 0.0)) {
        cout << -1;
        return 0;
    }
    int cur_n = n, cur_j = d;
    while (cur_n && cur_j >= 0) {
        if (path[cur_n][cur_j] <= 9) {
            ans.push_back(a[cur_n]);
        }
        cur_j = (path[cur_n][cur_j] == 11) ? cur_j : path[cur_n][cur_j];
        cur_n--;
    }
    sort(ans.begin(), ans.end());
    
    if (ans.size() == 0) {
        cout << -1;
        return 0;
    }
    cout << ans.size() << endl;
    for (int i : ans) {
        cout << i << ' ';
    }

}
