#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
int f[20], p[10], g[10];
int n, m;
char s[maxn];
int a[maxn], cnt[maxn];
int vis[maxn][maxn];
int main() {
  f[0] = 1;
  for (int i = 1; i <= 10; i++) f[i] = f[i - 1] << 1;
  p[1] = f[0] + f[2] + f[3] + f[5] + f[6] + f[7] + f[8] + f[9];
  p[2] = f[0] + f[4] + f[5] + f[6] + f[8] + f[9];
  p[3] = f[0] + f[1] + f[2] + f[3] + f[4] + f[7] + f[8] + f[9];
  p[4] = f[2] + f[3] + f[4] + f[5] + f[6] + f[8] + f[9];
  p[5] = f[0] + f[2] + f[6] + f[8];
  p[6] = f[0] + f[1] + f[3] + f[4] + f[5] + f[6] + f[7] + f[8] + f[9];
  p[7] = f[0] + f[2] + f[3] + f[5] + f[6] + f[8] + f[9];
  g[0] = 6;
  g[1] = 2;
  g[2] = 5;
  g[3] = 5;
  g[4] = 4;
  g[5] = 5;
  g[6] = 6;
  g[7] = 3;
  g[8] = 7;
  g[9] = 6;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    a[i] = (1 << 10) - 1;
    for (int j = 1; j <= 7; j++)
      if (s[j] == '1') a[i] = a[i] & p[j], cnt[i]++;
  }
  vis[n + 1][0] = 1;
  for (int i = n; i >= 1; i--) {
    for (int k = 0; k <= 9; k++)
      if (a[i] & f[k]) {
        for (int j = 0; j <= m; j++)
          vis[i][j] |= vis[i + 1][j - (g[k] - cnt[i])];
      }
  }
  if (!vis[1][m]) {
    puts("-1");
    return 0;
  }
  int m1 = m;
  for (int i = 1; i <= n; i++) {
    for (int k = 9; k >= 0; k--) {
      if ((a[i] & f[k]) && vis[i + 1][m1 - (g[k] - cnt[i])] &&
          (m1 >= (g[k] - cnt[i]))) {
        printf("%d", k);
        m1 -= g[k] - cnt[i];
        break;
      }
    }
  }
  return 0;
}
