#include <bits/stdc++.h>
using namespace std;
string s;
int n, k;
vector<string> digit = {"1110111", "0010010", "1011101", "1011011", "0111010",
                        "1101011", "1101111", "1010010", "1111111", "1111011"};
int main() {
  cin >> n >> k;
  getline(cin, s);
  vector<vector<int>> cost(n, vector<int>(10));
  vector<vector<bool>> posib(n + 1, vector<bool>(k + 1));
  for (int i = 0; i < n; ++i) {
    getline(cin, s);
    for (int j = 0; j < 10; ++j)
      for (int t = 0; t < 7; ++t) {
        if (digit[j][t] == '1' && s[t] == '0') ++cost[i][j];
        if (digit[j][t] == '0' && s[t] == '1') {
          cost[i][j] = -1;
          break;
        }
      }
  }
  posib[n][0] = true;
  for (int i = n - 1; i >= 0; --i)
    for (int j = 0; j <= k; ++j)
      for (int t = 0; t < 10 && posib[i + 1][j]; ++t)
        if (cost[i][t] != -1 && j + cost[i][t] <= k)
          posib[i][j + cost[i][t]] = true;
  if (!posib[0][k])
    cout << -1;
  else {
    int cont;
    for (int i = 0; i < n; ++i) {
      cont = -1;
      for (int j = 9; j >= 0; --j)
        if (cost[i][j] != -1 && k >= cost[i][j] &&
            posib[i + 1][k - cost[i][j]]) {
          cont = j;
          k -= cost[i][j];
          break;
        }
      cout << cont;
    }
  }
  return 0;
}
