#include <bits/stdc++.h>
using namespace std;
const int MXN = 2e3 + 10;
int q, n, k, ans;
int Cost[MXN][15];
string S[MXN];
vector<int> vec[MXN], Ans;
vector<string> Num = {"1110111", "0010010", "1011101", "1011011", "0111010",
                      "1101011", "1101111", "1010010", "1111111", "1111011"};
bitset<MXN> mark[MXN];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> S[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      bool f = 1;
      int now = 0;
      for (int h = 0; h < 7; h++) {
        if (S[i][h] == '1' && Num[j][h] == '0') f = 0;
        if (S[i][h] == '0' && Num[j][h] == '1') now++;
      }
      if (f) vec[i].push_back(now);
    }
  }
  mark[n][0] = 1;
  for (int i = n - 1; ~i; i--) {
    for (auto val : vec[i]) {
      mark[i] = mark[i] | (mark[i + 1] << val);
    }
  }
  for (int i = 0; i < n; i++) {
    bool found = 0;
    for (int j = 9; ~j; j--) {
      bool f = 1;
      int now = 0;
      for (int h = 0; h < 7; h++) {
        if (S[i][h] == '1' && Num[j][h] == '0') f = 0;
        if (S[i][h] == '0' && Num[j][h] == '1') now++;
      }
      if (f && now <= k && mark[i + 1][k - now]) {
        k -= now;
        Ans.push_back(j);
        found = 1;
        break;
      }
    }
    if (!found) return cout << -1, 0;
  }
  for (auto X : Ans) cout << X;
  return 0;
}
