#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
char ss[15][15] = {"1110111", "0010010", "1011101", "1011011", "0111010",
                   "1101011", "1101111", "1010010", "1111111", "1111011"};
char sss[15];
int num[15], nsiz[15], dp[maxn][maxn], used[maxn][maxn], d[maxn], siz[maxn],
    m[10], a[maxn][10];
vector<int> ans;
int main() {
  for (int i = 0; i < 10; i++) {
    int k = 0;
    for (int j = 0; j < 7; j++) {
      if (ss[i][j] == '1') k++, nsiz[i]++;
      if (j < 6) k <<= 1;
    }
    num[i] = k;
  }
  memset(used, -1, sizeof used);
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%s", sss);
    int len = strlen(sss);
    int k = 0;
    for (int j = 0; j < len; j++) {
      if (sss[j] == '1') k++, siz[i]++;
      if (j < len - 1) k <<= 1;
    }
    d[i] = k;
  }
  dp[n][0] = 1;
  for (int i = n; i; i--) {
    memset(m, -1, sizeof m);
    for (int j = 0; j < 10; j++) {
      if ((d[i] | num[j]) == num[j]) m[j] = nsiz[j] - siz[i];
      a[i][j] = m[j];
    }
    for (int j = 0; j < 10; j++)
      if (m[j] != -1)
        for (int t = 0; t <= k - m[j]; t++)
          if (dp[i][t]) dp[i - 1][t + m[j]] = 1;
  }
  if (!dp[0][k]) {
    puts("-1");
    return 0;
  }
  int now = k;
  for (int i = 0; i < n; i++) {
    for (int j = 9; j >= 0; j--) {
      if (a[i + 1][j] != -1 && now >= a[i + 1][j] &&
          dp[i + 1][now - a[i + 1][j]]) {
        printf("%d", j);
        now -= a[i + 1][j];
        break;
      }
    }
  }
  puts("");
}
