#include <bits/stdc++.h>   using namespace std;   using VI = vector<int>;   using PII = pair<int, int>;   using ll = long long;   const int M = 1e9 + 7;   const int N = 2010;   VI d{1110111, 10010,   1011101, 1011011, 111010,        1101011, 1101111, 1010010, 1111111, 1111011};   int GetDiff(int x, int y) {     return __builtin_popcount(x) - __builtin_popcount(y);   }   int Convert(int x) {     int s = 0, k = 1;     while (x) {       if (x % 10) s += k;       x /= 10;       k <<= 1;     }     return s;   }   int main() {     for (auto& v : d) v = Convert(v);     int n, k;     scanf( %d %d , &n, &k);     vector<VI> f(n + 1, VI(k + 1, -1));     VI a(n);     vector<vector<PII>> g(n);     for (int i = 0; i < n; ++i) {       int t;       scanf( %d , &t);       a[i] = t = Convert(t);       for (int j = 9; j >= 0; --j) {         if ((d[j] & t) == t) g[i].push_back({j, GetDiff(d[j], t)});       }     }     for (auto& v : g[n - 1])       f[n - 1][v.second] = max(f[n - 1][v.second], v.first);     for (int i = n - 2; i >= 0; --i) {       for (auto& v : g[i]) {         for (int j = 0; j < k + 1 - v.second; ++j) {           if (f[i + 1][j] != -1)             f[i][j + v.second] = max(f[i][j + v.second], v.first);         }       }     }     if (f[0][k] == -1)       puts( -1 );     else {       for (int i = 0; i < n; ++i) {         printf( %d , f[i][k]);         k -= GetDiff(d[f[i][k]], a[i]);       }       cout << endl;     }     return 0;   }   