#include <bits/stdc++.h>
using namespace std;
const int maxn = 2009;
string s[101] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                 "1101011", "1101111", "1010010", "1111111", "1111011"};
string in;
int n, K, val[maxn], dval[maxn];
bool f[maxn][maxn];
int main() {
  cin >> n >> K;
  for (int i = 0; i <= 9; i++)
    for (int j = 0; j < 7; j++)
      if (s[i][j] - '0') val[i] |= (1 << (7 - j - 1));
  for (int i = 1; i <= n; i++) {
    cin >> in;
    for (int j = 0; j < 7; j++)
      if (in[j] - '0') dval[i] |= (1 << (7 - j - 1));
  }
  f[n + 1][0] = 1;
  for (int i = n; i >= 1; i--)
    for (int j = 0; j <= 9; j++) {
      if ((val[j] & dval[i]) == dval[i]) {
        int w = (val[j] ^ dval[i]), num = 0;
        for (int k = 0; k < 7; k++)
          if (w & (1 << k)) num++;
        for (int k = num; k <= K; k++) f[i][k] |= f[i + 1][k - num];
      }
    }
  if (!f[1][K]) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 9; j >= 0; j--) {
      if ((val[j] & dval[i]) == dval[i]) {
        int w = (val[j] ^ dval[i]), num = 0;
        for (int k = 0; k < 7; k++)
          if (w & (1 << k)) num++;
        if (f[i + 1][K - num]) {
          cout << j;
          K -= num;
          break;
        }
      }
    }
  return 0;
}
