#include <bits/stdc++.h>
using namespace std;
constexpr int NMAX = 2005;
int a[NMAX];
int sol[NMAX];
int N, K;
int val[12];
int dp[NMAX][NMAX];
void Precalculare() {
  val[0] = 119;
  val[1] = 36;
  val[2] = 93;
  val[3] = 109;
  val[4] = 46;
  val[5] = 107;
  val[6] = 123;
  val[7] = 37;
  val[8] = 127;
  val[9] = 111;
}
int nrbiti(int value) {
  int nr = 0;
  for (int i = 0; (1 << i) <= value; ++i)
    if ((value & (1 << i))) ++nr;
  return nr;
}
int Cost(int x, int nou) {
  for (int i = 0; (1 << i) <= x; ++i)
    if ((x & (1 << i)) && (nou & (1 << i)) == 0) return -1;
  return nrbiti((x ^ nou));
}
void Solve() {
  for (int i = 0; i <= N; ++i)
    for (int j = 0; j <= K; ++j) dp[i][j] = -1;
  for (int cif = 9; cif >= 0; --cif) {
    int c = Cost(a[N], val[cif]);
    if (c == -1) continue;
    dp[N][c] = max(dp[N][c], cif);
  }
  for (int i = N - 1; i >= 1; --i)
    for (int nrbete = 0; nrbete <= K; ++nrbete)
      for (int cif = 9; cif >= 0; --cif) {
        int c = Cost(a[i], val[cif]);
        if (c == -1 || c > nrbete) continue;
        if (dp[i + 1][nrbete - c] == -1) continue;
        dp[i][nrbete] = cif;
        break;
      }
  if (dp[1][K] == -1)
    cout << -1 << '\n';
  else {
    int sol = K;
    for (int i = 1; i <= N; ++i) {
      cout << dp[i][sol];
      sol = sol - Cost(a[i], val[dp[i][sol]]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> K;
  Precalculare();
  for (int i = 1; i <= N; ++i) {
    char bit;
    for (int j = 0; j < 7; ++j) {
      cin >> bit;
      a[i] = a[i] + (1 << j) * (bit - '0');
    }
  }
  Solve();
  return 0;
}
