#include <bits/stdc++.h>
using namespace std;
int digit_to_int[] = {0b1110111, 0b0010010, 0b1011101, 0b1011011, 0b0111010,
                      0b1101011, 0b1101111, 0b1010010, 0b1111111, 0b1111011};
int int_to_digit[128];
short dp[2010][2010][10];
short segnum[2010][2010][10];
short pre[2010][2010][10];
int scoreboard[2010];
int main() {
  memset(int_to_digit, -1, sizeof(int_to_digit));
  for (int i = 0; i <= 9; i++) {
    int_to_digit[digit_to_int[i]] = i;
  }
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    char t[8];
    scanf("%s", t);
    for (int j = 0; j < 7; j++) {
      scoreboard[i] <<= 1;
      scoreboard[i] |= t[j] - '0';
    }
  }
  fill(dp[n][0], dp[n][0] + 10, 1);
  for (int i = n - 1; i >= 0; i--) {
    for (int d = 0; d <= 9; d++) {
      if ((scoreboard[i] & digit_to_int[d]) == scoreboard[i]) {
        int diff = __builtin_popcount(digit_to_int[d] - scoreboard[i]);
        for (int j = 0; j <= k; j++) {
          for (int m = 0; m <= 9; m++) {
            if (dp[i + 1][j][m]) {
              dp[i][j + diff][d] = 1;
              pre[i][j + diff][d] = m;
              segnum[i][j + diff][d] = diff;
            }
          }
        }
      }
    }
  }
  int cur = -1;
  for (int i = 9; i >= 0; i--) {
    if (dp[0][k][i]) {
      cur = i;
      break;
    }
  }
  if (cur == -1) {
    puts("-1");
    return 0;
  }
  printf("%d", cur);
  int seg = k;
  for (int i = 0; i < n - 1; i++) {
    int c = pre[i][seg][cur];
    int s = segnum[i][seg][cur];
    cur = c;
    seg -= s;
    printf("%d", cur);
  }
  return 0;
}
