#include <bits/stdc++.h>
using namespace std;
const char dig[10][8] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                         "1101011", "1101111", "1010010", "1111111", "1111011"};
int n, m;
char s[2022][8];
int det[2022][10];
bool f[2022][2022];
int calc(int id1, int id2) {
  int res = 0;
  for (int i = 0; i < 7; i++) {
    if (s[id1][i] == '0' && dig[id2][i] == '1') res++;
    if (s[id1][i] == '1' && dig[id2][i] == '0') return -1;
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i]);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 10; j++) det[i][j] = calc(i, j);
  memset(f, false, sizeof f);
  f[n + 1][0] = true;
  for (int i = n; i > 0; i--)
    for (int j = 0; j <= m; j++) {
      if (!f[i + 1][j]) continue;
      for (int k = 0; k < 10; k++)
        if (det[i][k] >= 0) f[i][j + det[i][k]] = true;
    }
  if (!f[1][m])
    puts("-1");
  else {
    int tot = 0;
    for (int i = 1; i <= n; i++)
      for (int j = 9; j >= 0; j--) {
        int x = det[i][j];
        if (x >= 0 && tot + x <= m && f[i + 1][m - tot - x]) {
          printf("%d", j);
          tot += x;
          break;
        }
      }
    puts("");
  }
  return 0;
}
