#include <bits/stdc++.h>
const int N = 2e3 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
using namespace std;
char num[10][10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                    "1101011", "1101111", "1010010", "1111111", "1111011"};
string s;
int a[N] = {0}, nu[10] = {0}, f[N][N], n;
int count(int x) {
  int sum = 0;
  while (x) {
    if (x & 1) sum++;
    x >>= 1;
  }
  return sum;
}
void dp(int x, int k) {
  if (x > n) return;
  int i;
  for (i = 9; i >= 0; i--)
    if ((a[x] & nu[i]) == a[x]) {
      int p = count(a[x] ^ nu[i]);
      if (k >= p && f[x + 1][k - p]) {
        cout << i;
        dp(x + 1, k - p);
        return;
      }
    }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int k, i, j, l;
  cin >> n >> k;
  for (i = 0; i <= 9; i++)
    for (j = 0; j < 7; j++)
      if (num[i][j] == '1') nu[i] |= (1 << j);
  for (i = 1; i <= n; i++) {
    cin >> s;
    for (j = 0; j < 7; j++)
      if (s[j] == '1') a[i] |= (1 << j);
  }
  f[n + 1][0] = 1;
  for (i = n; i >= 1; i--)
    for (j = 0; j <= 9; j++)
      if ((a[i] & nu[j]) == a[i]) {
        int add = count(a[i] ^ nu[j]);
        for (l = 0; l <= k - add; l++) f[i][l + add] |= f[i + 1][l];
      }
  if (!f[1][k])
    cout << -1 << endl;
  else
    dp(1, k);
  return 0;
}
