#include <bits/stdc++.h>
using namespace std;
char buffer[2000020], *p1, *p2;
template <class T>
void read(T& x) {
  char ch = ((p1 == p2 &&
              (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))
                 ? EOF
                 : *p1++);
  x = 0;
  bool f = 1;
  while (!('0' <= ch && ch <= '9') && ch != '-')
    ch = ((p1 == p2 &&
           (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))
              ? EOF
              : *p1++);
  if (ch == '-')
    f = 0,
    ch = ((p1 == p2 &&
           (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))
              ? EOF
              : *p1++);
  while ('0' <= ch && ch <= '9')
    x = (x << 1) + (x << 3) + ch - '0',
    ch = ((p1 == p2 &&
           (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))
              ? EOF
              : *p1++);
  x = (f) ? x : -x;
}
int _num[20];
template <class T>
void write(T x) {
  if (!x) {
    putchar('0'), putchar('\n');
    return;
  }
  if (x < 0) putchar('-'), x = -x;
  int c = 0;
  while (x) _num[++c] = x % 10, x /= 10;
  while (c) putchar('0' + _num[c--]);
  putchar('\n');
}
int bc[128];
int masks[] = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123};
int a[2020], res[2020];
int n, k;
bool vis[2020][2020], dp[2020][2020];
bool DP(int pos, int rest) {
  if (pos > n) return rest == 0;
  if (vis[pos][rest]) return dp[pos][rest];
  vis[pos][rest] = 1;
  bool& ans = dp[pos][rest];
  ans = false;
  for (register int i = 9; i >= 0; i--) {
    if ((a[pos] | masks[i]) != masks[i]) continue;
    if (rest < bc[masks[i] ^ a[pos]]) continue;
    if (DP(pos + 1, rest - bc[masks[i] ^ a[pos]])) {
      res[pos] = i;
      return ans = true;
    }
  }
  return ans;
}
int main() {
  bc[0] = 0;
  for (register int i = 1; i <= 127; i++) bc[i] = bc[i >> 1] + (i & 1);
  read(n), read(k);
  for (register int i = 1; i <= n; i++) {
    char ch =
        ((p1 == p2 &&
          (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))
             ? EOF
             : *p1++);
    while (ch != '0' && ch != '1')
      ch = ((p1 == p2 &&
             (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))
                ? EOF
                : *p1++);
    while (ch == '0' || ch == '1')
      a[i] = (a[i] << 1) + ch - '0',
      ch = ((p1 == p2 &&
             (p2 = (p1 = buffer) + fread(buffer, 1, 2000020, stdin), p1 == p2))
                ? EOF
                : *p1++);
  }
  if (!DP(1, k))
    printf("-1");
  else
    for (register int i = 1; i <= n; i++) printf("%d", res[i]);
  return 0;
}
