#include <bits/stdc++.h>
using namespace std;
string mat[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                "1101011", "1101111", "1010010", "1111111", "1111011"};
string act[2005];
queue<int>*qact, *qnxt;
vector<int> ans;
int dp[2005][2005];
int dif(string a, string b) {
  int rez = 0;
  for (int i = 0; i < a.size(); ++i) {
    if (a[i] == '1' && b[i] == '0') return -1;
    if (a[i] == '0' && b[i] == '1') rez++;
  }
  return rez;
}
int main() {
  long long n, k;
  qact = new queue<int>();
  qnxt = new queue<int>();
  memset(dp, -1, sizeof(dp));
  cin >> n >> k;
  dp[0][0] = 0;
  qnxt->push(0);
  for (int i = 1; i <= n; ++i) {
    cin >> act[i];
    swap(qact, qnxt);
    if (qact->empty()) {
      cout << -1 << '\n';
      return 0;
    }
    while (!qact->empty()) {
      long long j = qact->front();
      qact->pop();
      for (int nr = 9; nr >= 0; --nr) {
        int j2 = dif(act[i], mat[nr]);
        if (j2 == -1) continue;
        j2 += j;
        if (j2 > k) continue;
        if (dp[i][j2] == -1) {
          dp[i][j2] = nr;
          qnxt->push(j2);
        }
      }
    }
  }
  int i = n, j = k;
  while (i > 0) {
    if (dp[i][j] == -1) {
      cout << -1 << '\n';
      return 0;
    }
    ans.push_back(dp[i][j]);
    int diff = dif(act[i], mat[dp[i][j]]);
    j -= diff;
    i--;
  }
  for (int it = ans.size() - 1; it >= 0; --it) cout << ans[it];
  return 0;
}
