#include <bits/stdc++.h>
const int MAXN = 2009;
char c[10][9] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                 "1101011", "1101111", "1010010", "1111111", "1111011"};
char s[MAXN][9];
bool f[MAXN][MAXN];
int d[13];
int dist(char a[], char b[]) {
  int cnt = 0;
  for (int i = 0; i < 7; ++i)
    if (a[i] != b[i]) {
      if (a[i] == '1')
        return MAXN;
      else
        ++cnt;
    }
  return cnt;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%s", s[i]);
  for (int i = 1, k = n + 1; i < MAXN; ++i) f[k][i] = 0;
  f[n + 1][0] = 1;
  for (int i = n; i > 0; --i) {
    for (int j = 0; j < 10; ++j) d[j] = dist(s[i], c[j]);
    for (int j = 0; j <= m; ++j) {
      f[i][j] = 0;
      for (int k = 0; k < 10; ++k)
        if (j >= d[k]) f[i][j] |= f[i + 1][j - d[k]];
    }
  }
  if (!f[1][m]) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1, j = m; i <= n; ++i) {
    for (int k = 9; k >= 0; --k) {
      int w = dist(s[i], c[k]);
      if (j >= w && f[i + 1][j - w]) {
        printf("%d", k);
        j -= w;
        break;
      }
    }
  }
  printf("\n");
  return 0;
}
