#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int n, m, seq[maxn], ans[maxn], dp[maxn][maxn],
    s[10] = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123},
    c[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
inline int read() {
  register int ret = 0;
  register char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) {
    ret = (ret << 1) + ch - '0';
    ch = getchar();
  }
  return ret;
}
inline int cnt(int k) {
  register int ret = 0;
  while (k) {
    ret += (k & 1);
    k >>= 1;
  }
  return ret;
}
inline int check(int a, int x) {
  if ((s[x] | a) == s[x]) return c[x] - cnt(a);
  return 0x3f3f3f3f;
}
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; i++) seq[i] = read();
  memset(dp, -1, sizeof(dp));
  dp[n + 1][0] = 0;
  for (register int i = n; i; i--)
    for (register int j = 0; j <= m; j++)
      for (register int k = 0; k <= 9; k++)
        if (check(seq[i], k) != 0x3f3f3f3f && j >= check(seq[i], k) &&
            dp[i + 1][j - check(seq[i], k)] >= 0)
          dp[i][j] = k;
  if (dp[1][m] == -1)
    printf("-1\n");
  else
    for (register int i = 1; i <= n; i++) {
      printf("%d", dp[i][m]);
      m -= check(seq[i], dp[i][m]);
    }
  return 0;
}
