#include <bits/stdc++.h>
const int MAXN = 2000 + 5;
char GG[10][10] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                   "1101011", "1101111", "1010010", "1111111", "1111011"};
bool f[MAXN][MAXN];
int dis[(1 << 7) + 3][10];
int n, m;
char str[MAXN];
int a[MAXN];
int main() {
  for (int S = 0; S <= (1 << 7) - 1; ++S) {
    for (int j = 0; j <= 9; ++j) {
      bool flag = 1;
      for (int k = 0; k <= 6; ++k) {
        if ((((S >> k) & 1) == 1) && GG[j][k] == '0') {
          flag = 0;
          break;
        }
        if ((((S >> k) & 1) == 0) && GG[j][k] == '1') dis[S][j]++;
      }
      if (!flag) dis[S][j] = 1e9;
    }
  }
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", str);
    for (int k = 0; k <= 6; ++k)
      if (str[k] == '1') a[i] |= (1 << k);
  }
  f[n + 1][0] = 1;
  for (int i = n; i >= 1; --i) {
    for (int j = 0; j <= m; ++j) {
      if (!f[i + 1][j]) continue;
      for (int k = 0; k <= 9; ++k) {
        if (j + dis[a[i]][k] > m) continue;
        f[i][j + dis[a[i]][k]] = 1;
      }
    }
  }
  if (!f[1][m]) {
    puts("-1");
    return 0;
  }
  int now = m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 9; j >= 0; --j) {
      if (now - dis[a[i]][j] < 0) continue;
      if (!f[i + 1][now - dis[a[i]][j]]) continue;
      printf("%d", j);
      now -= dis[a[i]][j];
      break;
    }
  }
  puts("");
  return 0;
}
