#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

#define mk make_pair

const int MAX_N = 1E5 + 100;
const int MAX_D = 10;

int n, d;
double dp[MAX_N][MAX_D], logA[MAX_N];
pair<int, int> lst[MAX_N][MAX_D];
int a[MAX_N];
vector<int> ans;

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> d;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        logA[i] = log2(a[i]);
    }

    for (int i = 0; i < 10; ++i) {
        dp[0][i] = -1000000000;
        lst[0][i] = mk(-1, -1);
    }
    dp[0][1] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < 10; ++j) {
            dp[i][j] = dp[i - 1][j];
            lst[i][j] = lst[i - 1][j];
        }

        for (int j = 0; j < 10; ++j) {
            int k = j * a[i] % 10;
            if (dp[i][k] < dp[i - 1][j] + logA[i]) {
                dp[i][k] = dp[i - 1][j] + logA[i];
                lst[i][k] = mk(i - 1, j);
            }
        }
    }

    if (dp[n][d] < 0) {
        cout << -1 << endl;
    } else {
        auto u = lst[n][d];
        while (-1 != u.first) {
            ans.push_back(a[u.first + 1]);
            u = lst[u.first][u.second];
        }

        sort(ans.begin(), ans.end());
        if (0 == ans.size()) {
            cout << -1 << endl;
            return 0;
        }
        cout << ans.size() << endl;
        for (int u : ans) {
            cout << u << ' ';
        }
        cout << endl;
    }

    return 0;
}
