#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define case(t, c) cout<<"Case "<<t<<":"<<c

inline bool operator<(tuple<long double, int, int> &a, tuple<long double, int, int> &b) {
    if (get<1>(a) == get<1>(b))
        return get<0>(a) < get<0>(b);
    return get<1>(a) < get<1>(b);
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int n, d, y;
    cin >> n >> d;
    vector<pair<long double, int>> vc(n);
    for (auto &i : vc) {
        cin >> i.second;
        i.first = logl(i.second * 1.0);
    }

    if (d == 0) {
        bool five, two;
        two = five = false;
        for (auto &i : vc) {
            two |= i.second % 2 == 0;
            five |= i.second % 5 == 0;
        }
        if (two && five) {
            cout << n << endl;
            for (auto &i : vc) {
                cout << i.second << " ";
            }
            cout << endl;
        } else
            cout << -1 << endl;
        return 0;

    }
    vector<vector<tuple<long double, int, int>>> dp(n, vector<tuple<long double, int, int>>(10, {0.0, 0, -1}));
    for (int i = 0; i < n; ++i) {
        dp[i][vc[i].second % 10] = {vc[i].first, 1, -1};
    }
    for (int i = 1; i < vc.size(); ++i) {
        for (int j = 0; j < 10; ++j)
            dp[i][j] = max(dp[i][j], {get<0>(dp[i - 1][j]), get<1>(dp[i - 1][j]), j});
        for (int j = 0; j < 10; ++j) {
            if (get<1>(dp[i - 1][j]) > 0) {
                int digit = (j * vc[i].second) % 10;
                dp[i][digit] = max(dp[i][digit], {get<0>(dp[i - 1][j]) + vc[i].first, get<1>(dp[i - 1][j]) + 1, j});
            }
        }
    }

    if (get<1>(dp.back()[d]) == 0)
        cout << -1 << endl;
    else {
        cout << get<1>(dp.back()[d]) << endl;
        int i = n - 1, j = d;
        do {
            if (get<0>(dp[i][j]) != get<0>(dp[i - 1][j]) || get<1>(dp[i][j]) != get<1>(dp[i - 1][j])) {
                cout << vc[i].second << " ";
                j = get<2>(dp[i][j]);
            }

            i--;
        } while (i > 0 && get<2>(dp[i][j]) != -1);
        if (get<1>(dp[i][j]) == 1)
            cout << vc[i].second;
        cout << endl;
    }

    return 0;
}
