#include <bits/stdc++.h>
using namespace std;
int vis[2010][2010][11], vis1[2010][2010], g[2010][20];
string B[] = {"1110111", "0010010", "1011101", "1011011", "0111010",
              "1101011", "1101111", "1010010", "1111111", "1111011"},
       C[2010];
int f(string a) {
  int i, sum = 0;
  for (i = 0; i < a.size(); i++)
    if (a[i] == '1') sum++;
  return sum;
}
int ff(string a, string b) {
  int i;
  for (i = 0; i < a.size(); i++)
    if (a[i] == '0' && b[i] == '1') return 0;
  return 1;
}
int main() {
  int i, j, n, k, l, a, b;
  string x;
  cin >> n >> k;
  memset(g, -1, sizeof(g));
  for (i = 1; i <= n; i++) {
    cin >> C[i];
    for (j = 0; j <= 9; j++)
      if (ff(B[j], C[i])) g[i][j] = f(B[j]) - f(C[i]);
  }
  vis1[n + 1][0] = 1;
  for (i = n; i; i--) {
    for (j = 0; j <= k; j++) {
      for (l = 0; l <= 9; l++) {
        a = g[i][l];
        if (a >= 0 && j - a >= 0 && vis1[i + 1][j - a]) vis[i][j][l] = 1;
      }
      for (l = 0; l <= 9; l++)
        if (vis[i][j][l]) vis1[i][j] = 1;
    }
  }
  int ans = 0;
  for (j = 0; j <= 9; j++)
    if (vis[1][k][j]) ans = 1;
  if (ans) {
    a = k;
    for (i = 1; i <= n; i++) {
      for (j = 9; j >= 0; j--) {
        if (vis[i][a][j]) {
          printf("%d", j);
          a -= g[i][j];
          break;
        }
      }
    }
  } else
    printf("-1");
  return 0;
}
